Question: Using this pre given code: class Person implements Comparable { protected String name; protected int age; public Person(String name, int age) { this.name = name;

 Using this pre given code: class Person implements Comparable { protected

Using this pre given code:

class Person implements Comparable { protected String name; protected int age; public Person(String name, int age) { this.name = name; this.age = age; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String toString() { return String.format("%s(%d)", name, age); } }

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 [Employee[Susan(43), Bank tellers, 68000.00], Joe(21)] Person[] myList - new Person[2]; myList[o]-new Employee("Susan", 43, "Bank tellers",68000); myList[1]-new Person( "Joe", 21); System.out.println(Arrays.tostring (myList)); [Joe(21), Employee[ Susan(43), Bank tellers, 68000.00]] Person[] myList - new Person[2]; myList[o] -new Employee("Susan", 43, "Bank tellers",68000); myList[1]-new Person("Joe", 21); Arrays.sort (myList); System.out.println(Arrays.toString(myList))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!