/*An instance of this class represents an Employee who is paid every week by the hour. Overtime hours paid at 1.5 times the hourly pay rate. Constructors HourlyEmployee() //Create a new HourlyEmployee paid at Minimum-Wage HourlyEmployee(double rate) //Create a new HourlyEmployee //paid at a given hourly rate Accessors double getPayRate() double getTotalHours() Mutators void setPayRate(double rate) void addHours(double hours) void resetHours() Other Methods double grossPay() */ public class HourlyEmployee { //Class Constants public static final double MINIMUM_WAGE = 10.00; public static final int HOURS_LIMIT = 40; //Instance (State) Variables private double payRate; //Hourly Pay-Rate private double totalHours; //Total Hours Worked in the Week //Constructor: Create a new Minimum_Wage HourlyEmployee public HourlyEmployee() { this.setPayRate(MINIMUM_WAGE); this.resetHours(); } //Constructor: Create a new HourlyEmployee paid at a given pay-rate // @param payRate: The employee's hourly pay-rate public HourlyEmployee(double payRate) { this.setPayRate(payRate); this.resetHours(); } //Accessor - // @return: this HourlyEmployee's hourly pay-rate public double getPayRate() { return this.payRate; } //Accessor - // @return this HourlyEmployee's total hours for the week public double getTotalHours() { return this.totalHours; } //Mutator - // Update an HourlyEmployee's hourly pay-rate public void setPayRate(double rate) { this.payRate = rate < MINIMUM_WAGE ? MINIMUM_WAGE : rate; } //Mutator - // Update an HourlyEmployee's total hours for the week // @param hours: # hours to add to this HourlyEmployee's total hours public void addHours(double hours) { if (hours < 0.0) throw new RuntimeException("Invalid Hours: " + hours); this.totalHours = this.totalHours + hours; } //Mutator - // Clear an HourlyEmployee's total hours to 0 public void resetHours() { this.totalHours = 0.0; } // @return this HourlyEmployee's gross pay for all hours worked public double grossPay() { return this.totalHours * this.payRate + overtimePay(); } public String toString() { return "HOURLYEMPLOYEE Rate: $" + this.payRate + "/Hr. " + this.totalHours + " Hours"; } //Helper - // @return this HourlyEmployee's overtime pay // 0.0 if total hours < 40 private double overtimePay() { if (this.totalHours <= HOURS_LIMIT) return 0.0; return (this.totalHours - HOURS_LIMIT) * 0.5 * this.payRate; } }