Question: You will write a President class which implements the Comparable interface. You will write a driver class to create an ArrayList of President objects by

You will write a President class which implements the Comparable interface. You will write a driver class to create an ArrayList of President objects by reading in a comma separated file. You will write two classes that implement the parameterized Camparator interface. You will use the driver class to test classes.

a)Create a President class that implements Comparable Add implements Comparable to the class header. Do not parameterize Comparable. Create private state variables: String lastName, String firstName, String middleName, int orderNumber, String homeState Write a constructor with parameters to initialize each instance variable. Create public accessor methods to get each instance variable. Create public method getFullName, which returns a String in the form: lastName, firstName middleName. Override the equals and toString method inherited from the Object class. Use the @Override annotation above the method headers.equals will evaluate the presidents full names only. toString will return a formatted string in three left-justified columns. Use the static format method in the String class. full name, width 30 characters orderNumber, width 4 characters homeState, width 12 characters Implement the compareTo(Object obj) method. The return value is based on a comparison of the orderNumber. Use the @Override annotation above the method header.

b)PresidentNameComparator Class Create these two classes that implement the parameterized Comparator interface. Add implements Comparator to the class header. Implement the compare method. The return value will be based on the presidents full name in alphabetical order. Use the @Override annotation above the method headers.

c)PresidentHomeStateComparator Class Create these two classes that implement the parameterized Comparator interface. Add implements Comparator to the class header. Implement the compare method. The return value will be based on the presidents home state in alphabetical order. If the home state is the same, order by the presidents last name. If the last names are the same, order by first name. Use the @Override annotation above the method headers.

d)PresidentTester Class Create a PresidentTester class to test your classes. Add a main method. In main, create an ArrayList and fill it with President objects. Add a constructList method that takes in a String for the data file name and an ArrayList to fill. This method will read in the file and use it to create President objects and fill the ArrayList. Update main to call this method with the ArrayList..Use main to test the President classs compareTo methods, by sorting and looking at the results. Use Collections.sort method and print the results in: a. Order by full name b. Order by home state c. Order by president number

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!