Java Reference
In-Depth Information
Display 7.3
The Derived Class HourlyEmployee (part 1 of 3)
1 /**
2
Class Invariant: All objects have a name string, hire date, nonnegative
3
wage rate, and nonnegative number of hours worked. A name string of
4
"No name" indicates no real name specified yet. A hire date of
5 January 1, 1000 indicates no real hire date specified yet.
6 */
7 public class HourlyEmployee extends Employee
It will take the rest of Section
7.1 to explain this class
definition.
8 {
9
private double wageRate;
10
private double hours; //for the month
11
public HourlyEmployee()
12 {
If this line is omitted, Java will still invoke
the no-argument constructor for the
base class.
13 super();
14 wageRate = 0;
15 hours = 0;
16 }
17
/**
18
Precondition: Neither theName nor theDate is null;
19
theWageRate and theHours are nonnegative.
20
*/
21
public HourlyEmployee(String theName, Date theDate,
22
double theWageRate, double theHours)
23 {
24 super(theName, theDate);
25
if ((theWageRate >= 0) && (theHours >= 0))
27 wageRate = theWageRate;
28 hours = theHours;
26 {
29 }
30
else
31 {
33 "Fatal Error: creating an illegal hourly employee.");
34 System.exit(0);
32 System.out.println(
35 }
36 }
37
public HourlyEmployee(HourlyEmployee originalObject)
38 {
39
An object of the class
HourlyEmployee is also an
instance of the class Employee .
super (originalObject);
(continued)
 
Search WWH ::




Custom Search