Java Reference
In-Depth Information
Display 7.2
The Base Class Employee (part 1 of 2)
1 /**
3 A name string of "No name" indicates no real name specified yet.
2 Class Invariant: All objects have a name string and hire date.
4 A hire date of January 1, 1000 indicates no real hire date specified yet.
5 */
6 public class Employee
7 {
8 private String name;
The class Date is defined in
Display 4.13 .
9 private Date hireDate;
10
public Employee()
11 {
13 hireDate = new Date("January", 1, 1000); //Just a placeholder.
14 }
12 name = "No name";
/**
15
16
Precondition: Neither theName nor theDate is null .
*/
17
18
public Employee(String theName, Date theDate)
19 {
20
if (theName == null || theDate == null )
21 {
22 System.out.println("Fatal Error creating employee.");
23 System.exit(0);
24 }
25 name = theName;
26 hireDate = new Date(theDate);
27 }
28
public Employee(Employee originalObject)
29 {
30 name = originalObject.name;
31 hireDate = new Date(originalObject.hireDate);
32 }
33
public String getName()
34 {
35
return name;
36 }
37 public Date getHireDate()
38 {
39
return new Date(hireDate);
40 }
Search WWH ::




Custom Search