Question: Create a project called Lab3. Create a tester class called PersonSort and two classes that implement the Comparable interface one called the Person class and

Create a project called Lab3. Create a tester class called PersonSort and two classes that implement the Comparable interface one called the Person class and the other called the MyDate class. The Person class has a name and a birthdate. The name is a String object and the birthdate is a MyDate object. MyDate Class The MyDate class has three private instance variables: int month (1-12) int day (1-31) int year. It implements the Comparable interface. In the compareTo() method, make sure you check for year, month and day in that order. This class has two other methods: a three-parameter constructor that initializes the three instance variables (month, day and year) and an override of Objects toString() method that displays the date as month, day, and year. So the MyDate class has three public methods: MyDate (int month, int day, int year) int compareTo (MyDate obj) String toString() DO NOT create any other instance variables or methods. This is an immutable class. Person Class The Person class has two private instance variables: String name MyDate birthday It implements the Comparable interface. In the compareTo() method, compare the birthdays first, and then the names, using the compareTo() methods of the MyDate and String classes. It has two other methods: a four- parameter constructor that initializes the instance variables (name and birthday) passing three of the parameters to the MyDate birthday object in order to initialize it and an override of Objects toString method that displays the name and the birthday (using the toString method of the birthday object). So the Person class has three public methods: Person (String name, int month, int day, int year) int compareTo (Person obj) String toString() DO NOT create any other instance variables or methods. This is an immutable class. PersonSort Class The PersonSort class is the tester class for this program. It has four static methods: main, populate, selectionSort and insertionSort. The main method 1. creates an ArrayList (ArrayList) of Person objects 2. populates it from a file that is supplied to you 3. copies the ArrayList to another one 4. uses the first ArrayList and sorts it using an insertion sort algorithm 5. displays the sorted ArrayList 6. uses the second ArrayList and sorts it using a selection sort algorithm 7. displays the sorted ArrayList The populate method reads in the Person data from a file (see below for the format). See slide 99 for a good example of how to do this. DO NOT assume that you know how many records are in the file. It creates a Person object from each line in the file and adds the object to the first ArrayList. The selectionSort method sorts the ArrayList using the selection sort algorithm. The insertionSort method sorts the ArrayList using the insertion sort algorithm. You must implement these sorting algorithms. A version of this code is containined in the Lesson 3 Source Code. You are not permitted to use the sort method of the Collections framework, or its swap method. The Person objects must be sorted, first by birthday and then by name. The filename of the supplied file is Persons.txt. Place it in the src folder of either Eclipse or IntelliJ. Create a global static constant to hold the file name that will be passed to the File object for reading the file. DO NOT assume that you know how many records are in the file. static final String PERSON_FILE = ./src/Persons.txt; The format of the file is: name month day year You may use a try/catch block or let main throw the FileIO exception.

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!