/** A solution to the Employee problem. * @see http://www.radford.edu/itec120/2009spring-ibarland/Homeworks/hw05.html * @author Ian Barland * @version 2009.Mar.19 */ public class Employee { private double salary; // in $/hr. /** Employee constructor. * @param _salary The hourly wage (in dollars) for this Employee. */ Employee( double _salary ) { this.salary = _salary; } /** Returns how much this employee should be paid for a week's work * (including any overtime). * * @param hrsWorked How many hours this employee worked in a single week. * @return how much this employee should be paid for the week's work. */ double calcWeeklyPay( double hrsWorked ) { final int STD_WORK_WEEK = 40; // A named constant. double regularHrs; double overtimeHrs; if (hrsWorked <= STD_WORK_WEEK) { regularHrs = hrsWorked; overtimeHrs = 0; } else { regularHrs = STD_WORK_WEEK; overtimeHrs = hrsWorked - STD_WORK_WEEK; } return regularHrs*this.salary + overtimeHrs*this.salary*1.5; /* // Alternately, we could have initialize our vars using Math.min,max: double regularHrs = Math.min(hrsWorked, STD_WORK_WEEK); double overtimeHrs = Math.max(hrsWorked-STD_WORK_WEEK, 0); */ } }