-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweatherHub.java
60 lines (48 loc) · 2.06 KB
/
weatherHub.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
import java.util.ArrayList;
public class weatherHub {
private int knownStations = 0;
private String[] knownWeatherStations = new String[1000];
public ArrayList<WeatherHubStorage> weatherHubStorageList = new ArrayList<WeatherHubStorage>();
public void receiveData(double[][][][] data, String name, String location) {
// is the weather station known?
boolean known = false;
for (int i = 0; i < knownStations; i++) {
if (knownWeatherStations[i].equals(name + location)) {
weatherHubStorageList.get(i).addData(data);
System.out.println("Data added to known weather station");
}
}
}
public void setupWeatherStation(String pName, String pLocation) {
// is the name of the weather station and its location not already in use?
// search the list of weather stations for the name and location hyphenated together
for (int i = 0; i < knownStations; i++) {
if (knownWeatherStations[i].equals(pName + "-" + pLocation)) {
// if the name and location are already in use then exit the function
throw new IllegalArgumentException(
"The name and location of the weather station are already in use");
}
}
// create a new array of doubles in the format of the data that is sent to the weather hub
weatherHubStorageList.add(new WeatherHubStorage(pName, pLocation));
knownWeatherStations[knownStations] =
pName + "-" + pLocation; // add the name and location to the list of known weather stations
knownStations++; // increase the number of known weather stations by 1
}
public void listWeatherStations() {
for (int i = 0; i < knownStations; i++) {
System.out.println(knownWeatherStations[i]);
}
}
public void listWeatherStationData(String pName, String pLocation) {
for (int i = 0; i < knownStations; i++) {
if (knownWeatherStations[i].equals(pName + "-" + pLocation)) {
weatherHubStorageList.get(i).listData();
}
}
}
public int countWeatherStations() {
System.out.println(knownStations);
return knownStations;
}
}