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 January 1, 1000
5 indicates no real hire date specified yet.
6 */
7 public class HourlyEmployee extends Employee
8{
9
It will take the rest of Section
7.1 to explain this class
definition.
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))
26
{
27
wageRate = theWageRate;
28
hours = theHours;
29
}
30
else
31
{
32
System.out.println(
33
"Fatal Error: creating an illegal hourly employee.");
34
System.exit(0);
35
}
36
}
37
public HourlyEmployee(HourlyEmployee originalObject)
38
{
39
super (originalObject);
An object of the class
HourlyEmployee is also an
instance of the class Employee .
40
wageRate = originalObject.wageRate;
41
hours = originalObject.hours;
42
}
(continued)
 
Search WWH ::




Custom Search