Question: Mary Smith 2 8 2 3 4 - 3 4 - 1 7 6 5 John Zaremba 5 6 6 5 7 - 3 4
Mary Smith
John Zaremba
Elbert Dinwiddie
Egbert Dumpling
Delores Dinwiddie
Albert Anderson
David Levine
Henry Higgins
Zebulon Allen
Andrew Allan
Imelda McDougal
Mary Smith
Program name: PersonSelSort
above provided info is for this program with type of data. It is on our class Canvas page. The job of the program is to read n the data from above file use that data to populate an array named list of Person objects one Person object per each line of data in the input file. Once the data is all input, and all the data is captured in the list array of Person objects, then your program is to sort the elements of the array according to the compareTo method of the Person class. The sort is to be inplace and after the sort has completed the list array is now in sorted order, basically alphabetical order last name then first name and resorting to lexicographic order of socialsecurity numbers if full names are identical. The program completes by printing out a line at a time in sorted order the Person objects of the now sorted list array. We heavily depend upon the definition of the Person class that is given to you on our Canvas page in the sorting module
: There are two technical challenges in this program to do things not done in earlier programs. First your program is to read its input data from a file not from lines in standard typed input not from System.in Second the program is not sorting numbers as weve done in class it is sorting Person objects based on the compareTo method in the Person class.
FILE INPUT: For the first of these use a Scanner But instead of the Scanner being instantiated on System.in it should be constructedinstantiated on the File type object that has been built upon the file People.csv The Java class File is in the java package java.io so you will need to import java.ioFile or java.io and also import java.util.Scanner to get the Scanner So you can say:
File fptr new FilePeoplecsv;
Scanner sc new Scannerfptr;
In all cases of File IO things can go wrong and exceptions can happen as for example, the filenotfound exception. So you need to convince the compiler that you are aware of this. You can put the File activity the new File line in a trycatch block. Or you can simply say that the main method can throw an exception by giving the signature line of the main method.
GETTING THE LIST SORTED: So the program works like this. It reads in all the data from the file with the Scanner while loop and as it does this, it populates the list array and counts how many people it put in there. Then it calls the sorting function giving it the list array and the countvariable!
selectSortlist count;
The selectSort function does the magic and inplace sorts the list array. Once back from that function the list is sorted and you should print out each array element in order. Since we have a nice toString method in the Person class you can invoke it and print out each Person object in the list array by:
System.out.println listi;
SAMPLE RUN:
C:OPENJDKJavaCodeCSjava PersonSelSort
LIST BEFORE SORT
LIST AFTER SORT
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
