Question: Write a program which uses a two-dimensional array to store the first and last names of the 12 most recent U.S. presidents. The 12 most
Write a program which uses a two-dimensional array to store the first and last names of the 12 most recent U.S. presidents. The 12 most recent U.S. presidents are listed below. (Note that two were named George Bush.)
Dwight Eisenhower
John Kennedy
Lyndon Johnson
Richard Nixon
Gerald Ford
James Carter
Ronald Reagan
George Bush
William Clinton
George Bush
Barack Obama
Donald Trump
1.The first names should be stored in the first column (indexed by 0) and the last names should be stored in the second column (indexed by 1). For example, if the array is called names then names [0, 0] would be Dwight, names[0, 1] would be Eisenhower, names[1, 0] would be John, names[1, 1] would be Kennedy, names[2, 0] would be Lyndon, names[2, 1] would be Johnson, etc.
2.Write a method which accepts a reference to a two-dimensional array of Strings and sorts the array by the second column (i.e., by last name in this example). If two rows have the same value for the second column (as in the case of the two presidents named George Bush), the method should attempt to use the first column to break the tie if possible (although in the case of the two presidents named George Bush, there will still be a tie).
3.Write another method which accepts the first and last name of a president for which to search. The method should use a binary search to search the sorted array of names for the president entered by the user. The method should return the index of the row where a match was found or -1 if no match was found.
4.Write a method which accepts a reference to a two-dimensional array of Strings and prints the elements of the array with each row of the array printed on a separate line, and each column of the array separated by a space.
5.Write a main method which calls your helper methods to print the elements of the array before and after sorting the array. Once the array has been sorted, you main method should allow the user to enter the first and last name of a president to search for and then call your binary search method and display the results of the search.
Do not call any methods that come with Java which operate on entire arrays.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
