Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Where and what code needs to be incorporated to display the content of the array before using bubble sort. Thank you. TASK: Develop a program
Where and what code needs to be incorporated to display the content of the array before using bubble sort. Thank you.
TASK: Develop a program that asks the user to enter a capital for a US state. Upon receiving the user input, the program reports whether the user input is correct. For this application, the states and their capitals are stored in a twodimensional array in order by state name. Display the current contents of the array then use a bubble sort to sort the content by capital. Next, prompt the user to enter answers for all the state capitals and then display the total correct count. The user's answer is not casesensitive
MY SOLUTION:
import java.util.Scanner;
public class Test
Main method
public static void mainString args
Create a Scanner
Scanner input new ScannerSystemin;
Store states and their capitals in a twodimensional array
String statesAndCapitals getData;
int count ; Correct answer
Repeatedly prompt the user to enter the capital of a state
for int i ; i statesAndCapitals.length; i
System.out.printWhat is the capital of
statesAndCapitalsi;
String capital input.nextLine;
if isEqualstatesAndCapitalsi capital
System.out.printlnYour answer is correct";
count;
else
System.out.printlnThe correct answer should be
statesAndCapitalsi;
Display the total correct count
System.out.println
The correct count is count;
isEqual returns true if a is equal to c
public static boolean isEqualString c String a
if clength alength
return false;
for int i ; i clength; i
if ccharAti acharAti
return false;
return true;
getData initializes the array with the states and their capitals
public static String getData
String d
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"Indiana "Indianapolis"
Iowa Des", "Moines"Kansas "Topeka"Kentucky"Frankfort"
Louisiana "Baton Rouge"Maine "Augusta"
Maryland "Annapolis"Massachusetts "Boston"
Michigan "Lansing"Minnesota "Saint Paul"
Mississippi "Jackson"Missouri "Jefferson City"
Montana "Helena"Nebraska "Lincoln"
Nevada "Carson City"New Hampshire", "Concord"
New Jersey", "Trenton"New Mexico", "Santa Fe
New York", "Albany"North Carolina", "Raleigh"
North Dakota", "Bismarck"Ohio "Columbus"
Oklahoma "Oklahoma City"Oregon "Salem"
Pennsylvania "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";
return d;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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