-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployee.java
More file actions
37 lines (30 loc) · 909 Bytes
/
Employee.java
File metadata and controls
37 lines (30 loc) · 909 Bytes
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
public class Employee implements Comparable<Employee> {
private String name;
private int age;
public Employee(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
@Override
public int compareTo(Employee other) {
return Integer.compare(this.age, other.age);
}
@Override
public String toString() {
return "Employee{name='" + name + "', age=" + age + '}';
}
public static void main(String[] args) {
Employee e1 = new Employee("John", 25);
Employee e2 = new Employee("Jane", 30);
System.out.println("Test Case 1: " + e1.compareTo(e2));
e1 = new Employee("John", 30);
e2 = new Employee("Jane", 30);
System.out.println("Test Case 2: " + e1.compareTo(e2));
}
}