<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Here is some help for those of you struggling to get the array of
states built in Assignment 4. <br>
<pre>
<font face="serif">
<font face="Courier New, Courier, monospace"> /* At this point you should have processed all of your stations and have them in an array.
In the example below that array is called stations and it is of type Station (which is
defined in Station.java. Since you now have all of the station ID's and the states
that they are associated with, you can use that data to build an array of type State.
I'll give you a head start...
*/
int numberOfStates=1;
State[] stateData = new State[numberOfStates];
stateData[0] = new State( stations[0].getState() );
String state;
// I'm going to run through all of the stations in my array
for ( int i=1; i<stations.length; i++ ){
boolean found = false;
int j = 0;
// Now I'm going to look through the stateData array and see if the state
// that is tied the index i in the station array is already in the stateData array.
// If it is then I set the boolean found to true.
while ( j<stateData.length && !found ) {
if ( stations[i].getState().equals(stateData[j].getState())) {
found = true;
}
j++;
}
// If the state for index i in the stations array is already in the stateData array
// then I don't need to add it again. If it is NOT found in the stateData array,
// then I need to increase the size of my array and add the new data to the end.
// Look how similar this is to the last thing you did in processing the stations!
if (!found) {
State[] newstateData = new State[stateData.length+1];
for (int k=0; k<stateData.length; k++ ) newstateData[k] = stateData[k];
newstateData[newstateData.length-1] = new State(stations[i].getState());
stateData = newstateData;
}
}
// To make sure it is working, print out the states
for ( State s : stateData ) System.out.println(s.getState());
// Now - go fix your State.java file so it will work with what I have done above! You need
// to add the instance variables and methods (like getState to return the two character
// state abbreviation.
// Once you get this far you should be ready to start processing the daily.txt file.
</font></font>
</pre>
<br>
<pre class="moz-signature" cols="72">--
Andrew J. Pounds, Ph.D. (<a class="moz-txt-link-abbreviated" href="mailto:pounds_aj@mercer.edu">pounds_aj@mercer.edu</a>)
Professor of Chemistry and Computer Science
Mercer University, Macon, GA 31207 (478) 301-5627
<a class="moz-txt-link-freetext" href="http://faculty.mercer.edu/pounds_aj">http://faculty.mercer.edu/pounds_aj</a>
</pre>
</body>
</html>