Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(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 program's 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: California The capital is Sacramento. Enter a state, or "done" when finished: Northeast 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! m
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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