-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathEmployee.java
More file actions
57 lines (43 loc) · 1.62 KB
/
Employee.java
File metadata and controls
57 lines (43 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package OverrideExample;
import java.text.SimpleDateFormat;
import java.time.Month;
import java.util.Calendar;
import java.util.Date;
public class Employee extends Person {
private Date hireDate;
public static void main(String [] args) {
Calendar birthDate = Calendar.getInstance();
birthDate.set(1968, Month.JULY.ordinal(), 8);
Employee emp = new Employee("Jerod", "Wilkerson", birthDate.getTime(), new Date());
System.out.println(emp);
}
public Employee(String firstName, String lastName) {
this(firstName, lastName, null);
}
public Employee(String firstName, String lastName, Date birthDate) {
this(firstName, lastName, birthDate, null);
}
public Employee(String firstName, String lastName, Date birthDate, Date hireDate) {
// What happens if you comment out the super call? Why?
// What happens if you comment out the this calls in the other constructors?
super(firstName, lastName, birthDate);
this.hireDate = hireDate;
}
public Date getHireDate() {
return hireDate;
}
public void setHireDate(Date hireDate) {
this.hireDate = hireDate;
}
@Override
public String toString() {
String personString = super.toString();
personString = personString.replace("Person", "Employee");
personString = personString + "\b";
SimpleDateFormat dateFormat = new SimpleDateFormat("M/d/YYYY");
String formattedHireDate = dateFormat.format(hireDate);
return personString +
", hireDate=" + formattedHireDate +
'}';
}
}