Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider the Person, Student and Employee that we developed in Lab05 and the Comparable interface from the java.util package Interface Comparable f int compareTo(T o)
Consider the Person, Student and Employee that we developed in Lab05 and the Comparable interface from the java.util package Interface Comparablef int compareTo(T o) You are required to modify the Person class and implement the Comparable interface. You will need to override the compareTo (Person p) method. The comparison is based on the ages. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified Person Write the modified Person class in the answer box below assuming that the Student and Employee have been done for you For example Test Result Person[] myList - new Person[2]; myList[0]new Employee( Susan", 43, "Bank tellers", 68000) myList[1] = new Person("Joe", 21); System.out.println(Arrays.toString(myList)); [Employee Susan (43), Bank tellers, 68000.00], Joe (21)] Person[] myList -new Person[2] myList [0] = new Employee("Susan", 43, "Bank tellers", myList[1] = new Person("Joe", 21); Arrays.sort (myList); System.out.printIn(Arrays.toString(myList)); [Joe (21), Employee[Susan (43), Bank tellers, 68000.0011 68000); Answer (penalty regime: 0 %) 1 |class Person implements comparablePerson> { protected String name; protected int age; 4. public Person (String name, int age) { this.name name; this.age age; 7 9 18 public int getAge)t return age; 12 13 14 15 16 public void setAge(int age) this.age-age
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started