Skip to content

Instantly share code, notes, and snippets.

@unclebob
Created September 17, 2010 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unclebob/584517 to your computer and use it in GitHub Desktop.
Save unclebob/584517 to your computer and use it in GitHub Desktop.
package payroll;
public class PayCalculator {
public static double calculate(double hours,
double rate,
boolean isHourlyWorker) {
if (hours < 0 || hours > 80) {
throw new RuntimeException("Hours out of range: " + hours);
}
if (isHourlyWorker) {
double overtime = Math.max(0, hours - 40);
return hours * rate + overtime * rate * 0.5;
} else {
return hours * rate;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment