10.5.3 Concrete Subclass HourlyEmployee

Class HourlyEmployee (Fig. 10.6) also extends Employee (line 4). The class includes a constructor (lines 10–25) that receives a first name, a last name, a social security number, an hourly wage and the number of hours worked. Lines 28–35 and 44–51 declare set methods that assign new values to instance variables wage and hours, respectively. Method setWage (lines 28–35) ensures that wage is nonnegative, and method setHours (lines 44–51) ensures that the value of hours is between 0 and 168 (the total number of hours in a week) inclusive. Class HourlyEmployee also includes get methods (lines 38–41 and 54–57) to return the values of wage and hours, respectively; a method earnings (lines 60–67) to calculate ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.