-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployee.java
More file actions
66 lines (53 loc) · 1.57 KB
/
Employee.java
File metadata and controls
66 lines (53 loc) · 1.57 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
public class Employee {
private String name;
private int birthYear;
private String deptName;
public Employee() {
}
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;
}
// Other methods for Employee
@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 && name.equals(employee.name) && deptName.equals(employee.deptName);
}
@Override
public String toString() {
return String.format("Employee: Name: %s | Birth Year: %d | Department: %s", name, birthYear, deptName);
}
@Override
public int compareTo(Person p) {
if (p instanceof Employee) {
Employee otherEmployee = (Employee) p;
return Integer.compare(this.birthYear, otherEmployee.birthYear);
}
return -1;
}
}