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 i 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 Comparable i 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[] myListnew Person[2]; myList[0] = new Employee ("Susan", 43, "Bank tellers", myList[1] = new Person("Joe", 21); System.out.println(Arrays.toString(myList)); [Employee [Susan(43), Bank tellers, 68000.00], Joe (21)] 68000); Person [ ] myList new Person[2]; myList[0]new Employee("Susan", 43, "Bank tellers", 68000) myList[1]new Person("Joe", 21); Arrays.sort(myList); System.out.println(Arrays.tostring(myList)); Joe (21), Employee[Susan (43), Bank tellers, 68000.80]] Answer (penalty regime: 0 %) 1 class Person implements Comparable protected String name; protected int age; 4 5public Person(String name, int age) this.name name; this.age-age; public int getAge) return age; 10 12 13 14 15 16 17 18public String getName() 19 2e 21 public void setAge(int age) this.age age; return name; public void setName (String name) t 23 24 25 26 27 28 29 this.name name public String toString) return String.format("%s(%d)", name, 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