I've asked this question earlier today, but the answers didn't help me with my problem. Thought I could ask again with updated and hopefully closer to do my problem.
How do I show that Q is adjacent to X, R is adjacent to X (also), P is adjacent to R, etc etc...? Text File
Q X
R X
P R
P W
W S
S T
T W
W Y
Y R
Y Z
So it'd print to the screen:
Q is adjacent to X
R is adjacent to X
P is adjacent to R (tab or spaces) W
etc etc etc
Segment of code to read in the file and store them into two different ListArray's
while (theFlightFile.hasNext()) {
String cityFrom = theFlightFile.next();
String cityTo = theFlightFile.next();
City cityA = new City(cityFrom);
City cityB = new City(cityTo);
cityToList.add(cityA);
cityFromList.add(cityB);
//testing input reading...
//System.out.println(cityFrom + " -----> " + cityTo);
}
/**
* Displays to the screen, a list of all cities served by the airline
* along with the names of cities to which each is adjacent.
*/
public void displayFlightMap() {
int i = 0;
while (!cityStack.isEmpty() && topCity.equals(destinationCity)) {
displayAdjacentCities(cityFromList.get(i));
i++;
}
}
/**
* Displays to the screen, the names of all cities which are are adjacent
* to aCity; aCity is assumed to be a valid city served by the airline.
* @param aCity The city for which the adjacency list is desired.
*/
public void displayAdjacentCities(City aCity) {
String str = "";
for (City cityA : cityToList) {
for (City cityB : cityFromList) {
if (cityA != cityB) {
str = cityA + " is adjacent to " + cityB;
}
}
System.out.println(str);
}
}
What prints is what looks like cityToList printing 10 times and it all saying its adjacent to 'Z'