Question: JAVA program I do have Person.Java that store the data in in an ArrayList called People, where each element of the ArrayList is an Object
JAVA program
I do have Person.Java that store the data in in an ArrayList called People, where each element of the ArrayList is an Object containing a name, age, and weight. Always add new Objects to the end of the ArrayList. and Also created separate class called Peopletestmain with appropriate private variable that does set and get functions for each variable. The program should loop through the elements of the list captured by console and prints out the contents of each element separated by a space
Now need to add new methods to this program that needs to sort ArrayList by implementing the Comparable interface and the compareTo function in your Peopletestmain class. It then needs to print out the sorted ArrayList. It must sort the Persons first by forward-alphabetical name, then by increasing age, then by increasing weight in that order. You will print the ArrayList in a different format from Part I. You will need to create a toString() method in your test class to create the desired output below

Samuel 1 123 ENTER Sammie 2 234 ENTER Sammy 3 345 ENTER Sam 4 456 ENTER I 5 567 ENTER Am 6 678 ENTER stop ENTER Original list: [{Samuel, 1, 123.0}, {Sammie, 2, 234.0}, {Sammy, 3, 345.0}, {Sam, 4, 456.0}, {I, 5, 567.0}, {Am, 6, 678.0}] In In Sorted list: [{Am, 6, 678.0}, {I, 5, 567.0}, {Sam, 4, 456.0}, {Sammie, 2, 234.0}, {Sammy, 3, 345.0}, {Samuel, 1, 123.0}] Samuel 1 123 ENTER Sammie 2 234 ENTER Sammy 3 345 ENTER Sam 4 456 ENTER I 5 567 ENTER Am 6 678 ENTER stop ENTER Original list: [{Samuel, 1, 123.0}, {Sammie, 2, 234.0}, {Sammy, 3, 345.0}, {Sam, 4, 456.0}, {I, 5, 567.0}, {Am, 6, 678.0}] In In Sorted list: [{Am, 6, 678.0}, {I, 5, 567.0}, {Sam, 4, 456.0}, {Sammie, 2, 234.0}, {Sammy, 3, 345.0}, {Samuel, 1, 123.0}]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
