-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlightsPerAirport.pde
More file actions
49 lines (46 loc) · 1.62 KB
/
Copy pathFlightsPerAirport.pde
File metadata and controls
49 lines (46 loc) · 1.62 KB
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
class FlightsPerAirport{
ArrayList<DataPoint> flights;
ArrayList<String> airportNames;
ArrayList<Integer> numberOfFlights;
FlightsPerAirport(ArrayList<DataPoint> flights){
this.flights = flights;
for(DataPoint dp : flights){
if(airportNames==null){
airportNames = new ArrayList<String>();
airportNames.add(new String(dp.originAirport));
numberOfFlights = new ArrayList<Integer>();
numberOfFlights.add(1);
}
else if (newAirportCheck(dp.originAirport, airportNames)){
airportNames.add(new String(dp.originAirport));
numberOfFlights.add(1);
}
else if (!newAirportCheck(dp.originAirport, airportNames)){
numberOfFlights = addFlight(dp.originAirport, airportNames, numberOfFlights);
}
}
for (int i = 0; i < airportNames.size(); i++){
System.out.print(airportNames.get(i) + " ");
}
for (int i = 0; i < numberOfFlights.size(); i++){
System.out.print(numberOfFlights.get(i) + " ");
}
}
boolean newAirportCheck(String airport, ArrayList<String> airportList){
for (int i = 0; i < airportList.size(); i++){
if (airport.equals(airportList.get(i))){
return false;
}
}
return true;
}
ArrayList<Integer> addFlight(String airport, ArrayList<String> airportList, ArrayList<Integer> flightsNumber){
for (int i = 0; i < airportList.size(); i++){
if(airport.equals(airportList.get(i))){
int number = flightsNumber.get(i);
flightsNumber.set(i, ++number);
}
}
return flightsNumber;
}
}