-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneralStaff.java
More file actions
126 lines (103 loc) · 3.08 KB
/
GeneralStaff.java
File metadata and controls
126 lines (103 loc) · 3.08 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
public class Employee {
private String name;
private int birthYear;
private String deptName;
public Employee() {
// Default constructor
}
public Employee(String name, int birthYear, String deptName) {
this.name = name;
this.birthYear = birthYear;
this.deptName = deptName;
}
// Getters and setters for Employee attributes
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getBirthYear() {
return birthYear;
}
public void setBirthYear(int birthYear) {
this.birthYear = birthYear;
}
public String getDeptName() {
return deptName;
}
public void setDeptName(String deptName) {
this.deptName = deptName;
}
// Equals and toString methods
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
Employee employee = (Employee) obj;
return birthYear == employee.birthYear &&
Objects.equals(name, employee.name) &&
Objects.equals(deptName, employee.deptName);
}
@Override
public String toString() {
return "Employee{" +
"name='" + name + '\'' +
", birthYear=" + birthYear +
", deptName='" + deptName + '\'' +
'}';
}
}
public class GeneralStaff extends Employee {
private String duty;
public GeneralStaff() {
this.duty = "";
}
public GeneralStaff(String duty) {
this.duty = duty;
}
public GeneralStaff(String deptName, String duty) {
super.setDeptName(deptName);
this.duty = duty;
}
public GeneralStaff(String name, int birthYear, String deptName, String duty) {
super.setName(name);
super.setBirthYear(birthYear);
super.setDeptName(deptName);
this.duty = duty;
}
public String getDuty() {
return duty;
}
@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
return false;
}
GeneralStaff generalStaff = (GeneralStaff) obj;
return Objects.equals(duty, generalStaff.duty);
}
@Override
public String toString() {
return super.toString() + " GeneralStaff: Duty: " + duty;
}
}
public class Main {
public static void main(String[] args) {
GeneralStaff staff1 = new GeneralStaff();
GeneralStaff staff2 = new GeneralStaff("Coding");
GeneralStaff staff3 = new GeneralStaff("IT Department", "Testing");
GeneralStaff staff4 = new GeneralStaff("John Doe", 1990, "Finance", "Accounting");
System.out.println(staff1);
System.out.println(staff2);
System.out.println(staff3);
System.out.println(staff4);
System.out.println(staff1.equals(staff2));
System.out.println(staff2.equals(staff3));
System.out.println(staff3.equals(staff4));
}
}