Question
How can sort the data in the presidents.txt file, by last name or by date of birth in java. This problem will investigate one way
How can sort the data in the presidents.txt file, by last name or by date of birth in java. This problem will investigate one way to allow the user to easily sort by either field. (a) Create a President class which contains fields to store the name and birth date of a President (you can just use three int fields for the birth date). In addition, add a static field named sortBy and two static constants LASTNAME and BIRTHDATE. Add a method to allow the user to set the sortBy field to either of these constants. (b) Now modify the President class so that it implements the Comparable interface. The compareTo method should make use of the sortBy field. (c) Now write a driver program that opens the president.txt file, asks the user how they want the information sorted, and then sorts the data appropriately using Insertion Sort and writes it to the presidents_sorted.txt file.
The presidents.txt file
Eisenhower, Dwight David
10 14 1890
Kennedy, John Fitzgerald
05 29 1917
Johnson, Lyndon Baines
08 27 1908
Nixon, Richard Milhouse
01 09 1913
Ford, Gerald Rudolph
07 14 1913
Carter, Jimmy
10 01 1924
Reagan, Ronald Wilson
02 06 1911
Bush, George Herbert Walker
06 12 1924
Clinton, Bill J.
08 19 1946
Bush, George W.
07 06 1946
Obama, Barack Hussein
08 04 1961
Trump, Donald John
06 14 1946
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started