-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCampusRoute.java
More file actions
59 lines (42 loc) · 1.37 KB
/
Copy pathCampusRoute.java
File metadata and controls
59 lines (42 loc) · 1.37 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
50
51
52
53
54
55
56
57
58
59
// The route code
import java.util.*;
public class CampusRoute {
//Kamva
private final List<Stop> stops;
private final List<Bus> buses;
private final int numberOfStops;
//This is to create a circular route
private final int centerX = 400;
private final int centerY = 300;
private final int radius = 200;
public CampusRoute(int numberOfStops) {
this.numberOfStops = numberOfStops;
this.stops = new ArrayList<>(numberOfStops);
this.buses = new ArrayList<>();
for (int i = 0; i < numberOfStops; i++) {
stops.add(new Stop("Stop " + i));
}
}
public Stop getStop(int index) {
return stops.get(index % numberOfStops);
}
//I used Ai to ask for the coordination control
public int[] getStopCoordinates(int index) {
double angle = 2 * Math.PI * index / numberOfStops;
int x = (int) (centerX + radius * Math.cos(angle));
int y = (int) (centerY + radius * Math.sin(angle));
return new int[]{x, y};
}
public List<Stop> getStops() {
return stops;
}
public List<Bus> getBuses() {
return buses;
}
public void addBus(Bus bus) {
buses.add(bus);
}
public int getNumberOfStops() {
return numberOfStops;
}
}