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
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
c)PresidentHomeStateComparator Class Create these two classes that implement the parameterized Comparator
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
Get step-by-step solutions from verified subject matter experts
