Write a program that repeatedly prompts the user to enter a capital for a state.
ID: 3653683 • Letter: W
Question
Write a program that repeatedly prompts the user to enter a capital for a state. Upon receiving the user input, the program reports whether the answer is correct. Assume that 50 states and their capitals are stored in a two-dimensional array, as shown in figure 9.16. The program prompts the user to answer all states capitals and displays the total correct count. The user's answer is not case-sensitive. Figure 9.16 shows the state on one side and the capital on the other Alabama Montgomery Alaska Juneau .... ..... .... ..... The sample run: What is the capital of Alabama? user enters Montogomery The correct answer should be Montgomery What is the capital of Alaska? user enters Juneau Your answer is correct I'm only doing 5 states rather than the whole 50. I'm a little confused as to how to start this program. I declared my arrays by using string [ ] [ ] capitals = {states, capitals} then I used a if else to compare what the user enter is correct with the capital. I don't even know if it will compile correctly, and I need a counter to count the number of correct the user got. Am I suppose to use a for loop for the counter? Please help. ThanksExplanation / Answer
public class Lab5 { //Main Method public static void main(String[] args) { StateCapitals statecapitals1 = new StateCapitals(); // (A) statecapitals1.GetCapital(); // (B) JOptionPane.showInputDialog("What is the capital of " + statecapitals1.GetCapital()); JOptionPane.showMessageDialog(null,"Your answer is correct!"); } }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.