Question: (Find the capitals using maps) Write a program that will create a HashMap that maps the names of the 50 U.S. states to their corresponding
(Find the capitals using maps) Write a program that will create a HashMap that maps the names of the 50 U.S. states to their corresponding capitals. Your program will then repeatedly prompt the user to enter a state and will display the capital for the state, or an appropriate error message, until the user enters done. Your programs output should look like the sample shown below:
Enter a state, or "done" when finished: Texas
The capital is Austin.
Enter a state, or "done" when finished: Louisiana
The capital is Baton Rouge.
Enter a state, or "done" when finished: Southeast Texas
No such state.
Enter a state, or "done" when finished: done
Hint: To reduce the amount of coding, create a two dimensional array of Strings initialized to store the 50 states in the first column and their corresponding capital in the second column. Then within a loop access the elements of the array and put them in the HashMap.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
