Created
September 17, 2010 16:05
-
-
Save unclebob/584443 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package payroll; | |
public class PayCalculator { | |
public static float calculate(double hours, | |
double rate, | |
boolean isHourlyWorker) { | |
if (hours < 0 || hours > 80) { | |
throw new RuntimeException("Hours out of range: " + hours); | |
} | |
float wages = 0; | |
if (hours > 40) { | |
float overTimeHours = hours - 40; | |
if (isHourlyWorker) { | |
wages += (overTimeHours * 1.5) * rate; | |
} else { | |
wages += overTimeHours * rate; | |
} | |
hours -= overTimeHours; | |
} | |
wages += hours * rate; | |
return wages; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment