I have to read in a file that shows one letter (City) is adjacent to the other. They are separated by a tab.
How do I show that Q is adjacent to X, R is adjacent to X (also), P is adjacent to R, etc etc...?
Q X
R X
P R
P W
W S
S T
T W
W Y
Y R
Y Z
Segment of code to read in the file:
private ArrayList<City> cityList;
private ArrayList<City> cityFromList;
private ArrayList<City> cityToList;
Scanner theFlightFile = null;
try {
theFlightFile = new Scanner (new File("flightFile.txt"));
}
catch (Exception FileNotFoundException) {
System.out.println(FileNotFoundException.getMessage());
}
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);
}
Method to that displays the names of all the cities which are adjacent to 'aCity'. @param aCity The city for which the adjacency list is desired.
//this is completely wrong, I know...
public void displayAdjacentCities(City aCity) {
//for (aCity : cityFromList) {
// for (City cityB : cityToList) {
// System.out.println(cityA + " is adjacent to " + cityB);
// }
//}
}