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 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
Get step-by-step solutions from verified subject matter experts
