Question: Given the class Person below, create a new class called PersonComparator that implements the Comparator interface for objects of the class Person such that when

 Given the class Person below, create a new class called PersonComparator

Given the class Person below, create a new class called PersonComparator that implements the Comparator interface for objects of the class Person such that when the main method is called and myArray array is sorted, the computer output the array in descending order (see below). class Person { public String name; public String lastName; public Person(String name, String lastName) { this.name name; this. LastName lastName; public String getName(){ return name: public String getLastName(){ return lastName: public static void main(String arg(1) Person myArray[3] - new Person[3]; myArray[o] - new Person ("Robert","USAT) myArray[1] - new Person ("Andy", "UK")); wyArray[2] - new Person ("Harish", India) Arrays.sort(myArray, new Personcomparator()) for (Person person i myArray) System.out.println("My name is person.getName()); Output is My name is Robert My name is Harich My name is Andy

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!