Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Upon receiving the user input, the program reports whether the answer is correct

ID: 3653815 • Letter: U

Question

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 The sample run: Alabama ..... Montgomery Alaska.... Juneau

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. Thanks

Explanation / Answer

Java Code: import javax.swing.JOptionPane; public class Lab5 { //Main Method public static void main(String[] args) { StateCapitals statecapitals1 = new StateCapitals(); statecapitals1.GetCapital(); JOptionPane.showInputDialog("What is the capital of " + statecapitals1.GetCapital()); JOptionPane.showMessageDialog(null,"Your answer is correct!"); } } Java Code: class StateCapitals { private String[][] stateCapital = { {"Alabama", "Montgomery"}, {"Alaska", "Juneau"}, {"Arizona", "Phoenix"}, {"Arkansas", "Little Rock"}, {"California", "Sacramento"}, {"Colorado", "Denver"}, {"Connecticut", "Hartford"}, {"Delaware", "Dover"}, {"Florida", "Tallahassee"}, {"Georgia", "Atlanta"}, {"Hawaii", "Honolulu"}, {"Idaho", "Boise"}, {"Illinois", "Springfield"}, {"Maryland", "Annapolis"}, {"Minnesota", "Saint Paul"}, {"Iowa", "Des Moines"}, {"Maine", "Augusta"}, {"Kentucky", "Frankfort"}, {"Indiana", "Indianapolis"}, {"Kansas", "Topeka"}, {"Louisiana", "Baton Rouge"}, {"Oregon", "Salem"}, {"Oklahoma", "Oklahoma City"}, {"Ohio", "Columbus"}, {"North Dakota", "Bismark"}, {"New York", "Albany"}, {"New Mexico", "Santa Fe"}, {"New Jersey", "Trenton"}, {"New Hampshire", "Concord"}, {"Nevada", "Carson City"}, {"Nebraska", "Lincoln"}, {"Montana", "Helena"}, {"Missouri", "Jefferson City"}, {"Mississippi", "Jackson"}, {"Massachusettes", "Boston"}, {"Michigan", "Lansing"}, {"Pennslyvania", "Harrisburg"}, {"Rhode Island", "Providence"}, {"South Carolina", "Columbia"}, {"South Dakota", "Pierre"}, {"Tennessee", "Nashville"}, {"Texas", "Austin"}, {"Utah", "Salt Lake City"}, {"Vermont", "Montpelier"}, {"Virginia", "Richmond"}, {"Washington", "Olympia"}, {"West Virginia", "Charleston"}, {"Wisconsin", "Madison"}, {"Wyoming", "Cheyenne"} }; protected String [][] GetCapital() { return stateCapital; } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote