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 28234-34-1765
John Zaremba 56657-34-0789
Elbert Dinwiddie 49345-98-1234
Egbert Dumpling 64345-34-1865
Delores Dinwiddie 50345-56-8759
Albert Anderson 35234-34-5432
David Levine 33451-89-5467
Henry Higgins 56657-34-8765
Zebulon Allen 34234-65-2345
Andrew Allan 27569-34-4387
Imelda McDougal 43657-34-1232
Mary Smith 45145-90-3214
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 in-place 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 social-security 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).
2: 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 constructed/instantiated 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.io.File (or java.io.*) and also import java.util.Scanner (to get the Scanner). So, you can say:
File fptr = new File("People.csv");
Scanner sc = new Scanner(fptr);
In all cases of File I/O, things can go wrong and exceptions can happen as, for example, the file-not-found 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 try/catch 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!
selectSort(list, count);
The selectSort() function does the magic and in-place 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( list[i]);
SAMPLE RUN:
C:\OPENJDK\JavaCode\CS2050>java 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 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 Accounting Questions!