-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cities.java
66 lines (53 loc) · 1.9 KB
/
Cities.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import javax.crypto.Cipher;
import java.io.*;
import java.util.*;
import java.lang.System;
public class Cities {
// TODO: Next step: Remove the enum completely and change the rest of the classes to
// use the cityCount() function instead of cities.length
// All instances of Cities.cities need to be replaced with a for loop and an int
// Need to figure out how to acces Cities through BruteForce
List<String> names = new ArrayList<>();
public int size;
public List<City> cities = new ArrayList<>();
public int cityCount() {
return cities.size();
}
public City lookup(String string) // Finds the city that the string is related to
{
for (City c: cities) {
if (Objects.equals(string, c.name))
return c;
}
return null;
}
public void getCities(String configFileName){
// We read the cities from the config file here
System.out.println("Reading config file: " + configFileName);
File configFile = null;
Scanner reader = null;
try {
configFile = new File(configFileName);
reader = new Scanner(configFile);
} catch (FileNotFoundException e) {
System.out.println("File not found");
System.exit(0);
}
if (reader.hasNext()) {
// The first line has the list of cities
String line = reader.nextLine();
String[] str = line.split(",");
for (String s : str) {
names.add(s.trim());
}
size = names.size();
System.out.println( "Cities: " );
for (int i = 0; i < names.size(); i++) {
City c = new City (i,names.get(i).trim());
cities.add(c);
System.out.print(c.name + ", ");
}
}
System.out.println("Reading connections");
}
}