G.10.3. Concrete Subclass HourlyEmployee
Class HourlyEmployee
(Fig. G.18) also extends Employee
(line 4). The class includes a constructor (lines 10–16) that takes as arguments a first name, a last name, a social security number, an hourly wage and the number of hours worked. Lines 19–26 and 35–42 declare set methods that assign new values to instance variables wage
and hours
, respectively. Method setWage
(lines 19–26) ensures that wage
is nonnegative, and method setHours
(lines 35–42) ensures that hours
is between 0 and 168 (the total number of hours in a week) inclusive. Class HourlyEmployee
also includes get methods (lines 29–32 and 45–48) to return the values of wage
and hours
, respectively; a method earnings
(lines 51–58) to calculate an ...
Get Android™ How to Program, Second 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.