Question
I created 3 classes for code below: this is the first class: public class StateListIMP { public static void main(String[] args) { StateList sl=new StateList();
I created 3 classes for code below:
this is the first class:
public class StateListIMP {
public static void main(String[] args)
{
StateList sl=new StateList();
//LOAD FROMFILE
try
{
sl.LoadStateFile();
}
catch(Exception EXP12)
{
EXP12.printStackTrace();
}
//SEARCH FOR STATE INFO
sl.SearchState();
//PRINT STATE LIST
sl.printStateList();
}
}
the second class:
import java.io.*;
import java.lang.*;
import java.util.*;
class StateList
{
ListNode nodeHead;
// LinkedList constructor
public StateList()
{
nodeHead = null;
}
//LOAD STATE INFO FROMFILE
public void LoadStateFile()throws Exception
{
//BUFFEREDREADER TO READ FROMFILE
BufferedReader b=new BufferedReader(new FileReader("statedata.txt"));
String stateName;
//READ UNTIL THERES IS INFO
while((stateName=b.readLine())!=null)
{
String stateCapital=b.readLine();
int pop=Integer.parseInt(b.readLine());
ListNode t = new ListNode(stateName,stateCapital,pop);
ListNode crList = nodeHead;
if(nodeHead==null)
{
nodeHead=t;
}
else
{
t.setNextLink(nodeHead);
nodeHead=t;
}
}
b.close();//CLOSE BUFFEREDREADER
}
//SEARCH FOR THE GIVEN STATE
public void SearchState()
{
Scanner list_Scan12=new Scanner(System.in);
System.out.println("Enter state name tosearch:");
String stName= list_Scan12.nextLine();
ListNode crList = nodeHead;
while(crList != null)
{
if(crList.getStateName().equals(stName))
{
System.out.println("State Capital:"+crList.getStateCapital());
System.out.println("State Population:"+crList.getStatePopulation());
return;
}
else
crList = crList.getNextLink();
}
System.out.println("State is not found in list");
}
//PRINT STATES IN THE LINKEDLIST
public void printStateList()
{
ListNode crList = nodeHead;
System.out.println("STATE LIST");
while(crList != null)
{
System.out.println("State Name:"+crList.getStateName()+" Capital:"+crList.getStateCapital()+" Population:"+crList.getStatePopulation());
crList = crList.getNextLink();
}
}
}
the third class:
class ListNode { //VARIABLESFOR STATE NAME, CAPITAL POPULATION
ListNode nxtLink;
String name;
String capital;
int population;
public ListNode(String stName,String stCapital,int stPop)
{
name=stName;
capital=stCapital;
population=stPop;
nxtLink=null;
}
//CONSTRUCTOR
public ListNode(String stName,String stCapital,int stPop, ListNode _nxtLink)
{
nxtLink = _nxtLink;
name=stName;
capital=stCapital;
population=stPop;
}
//GET STATE NAME
public String getStateName()
{
return name;
}
public void setStateName(String stName)
{
name=stName;
}
//GET STATE CAPITAL
public String getStateCapital()
{
return capital;
}
public void setStateCapital(String stCapital)
{
capital=stCapital;
}
//GET STATE POPULATION
public int getStatePopulation()
{
return population;
}
public void setStatePopulation(int stPop)
{
population=stPop;
}
//GET NEXT NODE
public ListNode getNextLink()
{
return nxtLink;
}
//SET LINK
public void setNextLink(ListNode _nxtLink)
{
nxtLink = _nxtLink;
}
}
the resutl comed out like this:
run:
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:592)
at java.lang.Integer.parseInt(Integer.java:615)
at statelistimp.StateList.LoadStateFile(StateList.java:52)
at statelistimp.StateListIMP.main(StateListIMP.java:26)
Enter state name tosearch:
Alaska
State Capital:Juneau
State Population:738432
STATE LIST
State Name:Wyoming Capital:Cheyenne Population:586107
State Name:Wisconsin Capital:Madison Population:5771337
State Name:West Virginia Capital:Charleston Population:1844128
State Name:Washington Capital:Olympia Population:7170351
State Name:Virginia Capital:Richmond Population:8382993
State Name:Vermont Capital:Montpelier Population:626042
State Name:Utah Capital:Salt Lake City Population:2995919
State Name:Texas Capital:Austin Population:27469114
State Name:Tennessee Capital:Nashville Population:6600299
State Name:South Dakota Capital:Pierre Population:858469
State Name:South Carolina Capital:Columbia Population:4896146
State Name:Rhode Island Capital:Providence Population:1056298
State Name:Pennsylvania Capital:Harrisburg Population:12802503
State Name:Oregon Capital:Salem Population:4028977
State Name:Oklahoma Capital:Oklahoma City Population:3911338
State Name:Ohio Capital:Columbus Population:11613423
State Name:North Dakota Capital:Bismarck Population:756927
State Name:North Carolina Capital:Raleigh Population:10042802
State Name:New York Capital:Albany Population:19795791
State Name:New Mexico Capital:Santa Fe Population:2085109
State Name:New Jersey Capital:Trenton Population:8958013
State Name:New Hampshire Capital:Concord Population:1330608
State Name:Nevada Capital:Carson City Population:2890845
State Name:Nebraska Capital:Lincoln Population:1896190
State Name:Montana Capital:Helena Population:1032949
State Name:Missouri Capital:Jefferson City Population:6083672
State Name:Mississippi Capital:Jackson Population:2992333
State Name:Minnesota Capital:Saint Paul Population:5489594
State Name:Michigan Capital:Lansing Population:9922576
State Name:Massachusetts Capital:Boston Population:6794422
State Name:Maryland Capital:Annapolis Population:6006401
State Name:Maine Capital:Augusta Population:1329328
State Name:Louisiana Capital:Baton Rouge Population:4670724
State Name:Kentucky Capital:Frankfort Population:4425092
State Name:Kansas Capital:Topeka Population:2911641
State Name:Iowa Capital:Des Moines Population:3123899
State Name:Indiana Capital:Indianapolis Population:6619680
State Name:Illinois Capital:Springfield Population:12859995
State Name:Idaho Capital:Boise Population:1654930
State Name:Hawaii Capital:Honolulu Population:1431603
State Name:Georgia Capital:Atlanta Population:10214860
State Name:Florida Capital:Tallahassee Population:20271272
State Name:Delaware Capital:Dover Population:945934
State Name:Connecticut Capital:Hartford Population:3590886
State Name:Colorado Capital:Denver Population:5456574
State Name:California Capital:Sacramento Population:39144818
State Name:Arkansas Capital:Little Rock Population:2978204
State Name:Arizona Capital:Phoenix Population:6828065
State Name:Alaska Capital:Juneau Population:738432
what is the problem?
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