-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeneralStaff.java
66 lines (48 loc) · 1.77 KB
/
GeneralStaff.java
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
58
59
60
61
62
63
64
65
66
public class GeneralStaff extends Employee{
private String duty;
public GeneralStaff() { // duty = “”
super();
duty = "";
}
public GeneralStaff(String duty) {
this.duty = duty;
}
public GeneralStaff(String deptName, String duty) {
super(deptName);
this.duty = duty;
}
public GeneralStaff(String name, int birthYear, String deptName, String duty) {
super(name,birthYear,deptName);
this.duty = duty;
}
public String getDuty() {
return duty;
}
@Override
public boolean equals(Object obj) { //all attributes inherited+local must match for 2 Staff objects to be considered equal
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof GeneralStaff)) { // if object is an instance of a class it has access to all the methods and properties(variables) defined by the class
return false;
}
GeneralStaff staff = (GeneralStaff) obj; //we cast GeneralStaff as an object to compare all instance fields to itself(the class)
if (duty != staff.duty) {
return false;
}
return true;
}
@Override
public String toString() { //”<content of Employee> GeneralStaff: Duty: %10s”, duty
return String.format("%s GeneralStaff: Duty: %10s",super.toString(), duty);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
// GeneralStaff c = new GeneralStaff("Fidel Castro",1926,"Revolution","clean");
// System.out.println(c.toString()); //you dont pass employee number as a parameter since that is assigned within the employee constructor and it increments
//everytime we create an object
}
}