Hello I need to add lines to the following code to get an output like the one at the bottom: JAVA File: import java.util

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Hello I need to add lines to the following code to get an output like the one at the bottom: JAVA File: import java.util

Post by answerhappygod »

Hello I need to add lines to the following code to get an output
like the one at the bottom:
JAVA File:
import java.util.*;
import java.io.*;
public class Capitals
{
public static void main(String[] args)
{
HashMap capNStates = readData("States_Capital.csv");
ArrayList states = new
ArrayList<>(capNStates.keySet());
String state = states.remove(10);
System.out.println( capNStates.get(state) );
}
public static HashMap readData( String filename )

{
//exception handling
try
{
HashMap data = new HashMap<>();
File f = new File( filename );
Scanner scan = new Scanner(f);
while( scan.hasNextLine () )
{
String[] line = scan.nextLine.split(",");
data.put( line[0], line[1] );
}
return data;
}catch(FileNotFoundException e)
{
System.out.println( filename + " not found ");
return null;
}
}
}
This is how the output should look like:
Hello I Need To Add Lines To The Following Code To Get An Output Like The One At The Bottom Java File Import Java Util 1
Hello I Need To Add Lines To The Following Code To Get An Output Like The One At The Bottom Java File Import Java Util 1 (20.88 KiB) Viewed 81 times
Since I cannot provide the CSV File, here's a picture of what it
looks like:
Hello I Need To Add Lines To The Following Code To Get An Output Like The One At The Bottom Java File Import Java Util 2
Hello I Need To Add Lines To The Following Code To Get An Output Like The One At The Bottom Java File Import Java Util 2 (61.28 KiB) Viewed 81 times
Score: 0 State: delaware Capital: edvro dover Score: 5 State: new york Capital: lbnyaa albany Score: 10 State: west virginia Capital: nroehtalsc rochester Score: 8 State: West Virginia Capital: norcteslah quit

A B 1 Alabama Montgomery 2 Alaska Juneau 3 Arizona Phoenix 4 Arkansas Little Rock 5 California Sacramento 6 Colorado Denver Connecticut Hartford 7 8 9 8 Delaware Dover 9 Florida Tallahassee 10 Georgia Atlanta 11 Hawaii Honolulu 12 Idaho 13 Illinois 14 Indiana Boise Springfield Indianapolis Des Moines Topeka 15 lowa 16 Kansas 17 Frankfort Kentucky Louisiana 18 Baton Rouge 19 Maine Augusta Annapolis 20 Maryland 21 Massachusetts Boston 22 Michigan Lansing Saint Paul 23 Minnesota 24 Mississippi Jackson 25 Missouri Jefferson City
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply