public void Data(String inputString) throws IOException { boolean pass = true; B
ID: 3651102 • Letter: P
Question
public void Data(String inputString) throws IOException{
boolean pass = true;
BufferedWriter found;
found = new BufferedWriter(new FileWriter("ErrorFile.2.txt"));
try
{
stateName = inputString.substring(0,15).trim();
capitalName = inputString.substring(15,30).trim();
stateAbbreviation = inputString.substring(30,32);
statePopulation = Integer.parseInt(inputString.substring(32,40).trim());
stateRegion = inputString.substring(40,55);
stateRegionNum = Integer.parseInt(inputString.substring(55,56).trim());
} //end try
catch (NumberFormatException nfe)
{
population = inputString.substring(40).trim();
Error1 = (inputString + " BAD INPUT: Bad/Invalid Population Value: "
+ population + " ");
errorfile += Error1;
found.write(errorfile);
pass = false;
System.err.println("errorfile");
} //end catch
try
{
stateRegionNum = Integer.parseInt(inputString.substring(55, 56).trim());
} //end try
catch (NumberFormatException nfe)
{
regionNum = inputString.substring(55, 56).trim();
Error2 = (inputString + " BAD INPUT: Bad/Missing Region Number: "
+ regionNum + " " );
errorfile += Error2;
found.write(errorfile);
pass = false;
} //end catch
if (stateRegionNum < 1 || stateRegionNum > 4)
{
region = inputString.substring(55, 56).trim();
Error3 = (inputString + " BAD INPUT: Bad/Invalid Region Number: "
+ region + " ");
errorfile += Error3;
found.write(errorfile);
pass = false;
} //end if loop
if (pass) //if pass is true then a state object is then created
{
State array = new State();
array.setStateName (stateName);
array.setCapitalName (capitalName);
array.setStateRegion (stateRegion);
array.setStateRegionNum (stateRegionNum);
array.setStatePopulation (statePopulation);
array.setStateAbbreviation (stateAbbreviation);
switch (array.getStateRegionNum())//selects and adds each state to arraylist according to region regionNum
{
case 1:
StateArray[0].add(array);
break;
case 2:
StateArray[1].add(array);
break;
case 3:
StateArray[2].add(array);
break;
case 4:
StateArray[3].add(array);
break;
} //end switch
index++;
} //end if loop
found.close(); //close bw file
} //end initalize()
/**
* Builds the four queue objects for each of the four regions.
* @return none
* @param none
*/
public void makeQueue()
{
State tempQueue;
if (StateArray[0].size() > 8)//passes each state item to the insert() method
{
System.out.println(" North States Changes ");
System.out.println("-------------------------------------------- ");
} //end if loop
for (int nCount = 0; nCount < StateArray[0].size(); nCount++)
{
tempQueue = StateArray[0].get(nCount);
NorthQueue.insert(tempQueue);
} //end for loop
if (StateArray[1].size() > 8)
{
System.out.println(" Western States Changes ");
System.out.println("-------------------------------------------- ");
} //end if loop
for (int wCount = 0; wCount < StateArray[1].size(); wCount++)
{
tempQueue = StateArray[1].get(wCount);
WestQueue.insert(tempQueue);
} //end for loop
if (StateArray[2].size() > 8)
{
System.out.println(" Eastern States Changes ");
System.out.println("-------------------------------------------- ");
} //end if loop
for (int eCount = 0; eCount < StateArray[2].size(); eCount++)
{
tempQueue = StateArray[2].get(eCount);
EastQueue.insert(tempQueue);
} //end for loop
if (StateArray[3].size() > 8)
{
System.out.println(" Central States Changes ");
System.out.println("-------------------------------------------- ");
} //end if loop
for (int cCount = 0; cCount < StateArray[3].size(); cCount++)
{
tempQueue = StateArray[3].get(cCount);
CentralQueue.insert(tempQueue);
} //end for loop
} //end makeQueue()
/**
* Displays headers and the State Queues.
* @return none
* @param none
*/
public void displayQueue()
{
System.out.println(" North States Circular Queue ");
System.out.println("-------------------------------------------- ");
System.out.println(NorthQueue + " ");
System.out.println(" West States Circular Queue ");
System.out.println("-------------------------------------------- ");
System.out.println(WestQueue + " ");
System.out.println(" East States Circular Queue ");
System.out.println("-------------------------------------------- ");
System.out.println(EastQueue + " ");
System.out.println(" Central States Circular Queue ");
System.out.println("-------------------------------------------- ");
System.out.println(CentralQueue + " ");
} //end displayQueue()
/**
* Deletes state objects from the Queue objects.
* @return none
* @param none
*/
public void deleteQueue()
{
//calls deleteState() to delete state objects from the
//eastern and western Queue
System.out.println("Removal of Four Objects from East State(s)");
System.out.println("------------------------------------------- ");
EastQueue.deleteState();
System.out.print(" ");
System.out.println("Removal of Four Objects from West State(s)");
System.out.println("------------------------------------------- ");
WestQueue.deleteState();
System.out.print(" ");
} //end deleteQueue()
/**
* Displays Eastern and Western queues after deletions.
* @return none
* @param none
*/
Explanation / Answer
there is no main function in your java code java code should have class which is having public static void main ( String args[]){ } this function in your java code
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.