-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLine.java
More file actions
102 lines (96 loc) · 2.46 KB
/
Line.java
File metadata and controls
102 lines (96 loc) · 2.46 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//Create the Line class
import java.util.ArrayList;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
public class Line implements Serializable{
private static final long serialVersionUID = 10;
protected String name;
protected Location departure;
protected Location destination;
protected Time first;
protected Time last;
protected int period;
protected ArrayList <BusStop> route;
protected ArrayList <Integer> timePoints;
protected ArrayList<Time> times;
protected int timePointAmount;
public Line () {
name = "";
departure = null;
destination = null;
first = null;
last = null;
period = 0;
route = new ArrayList<BusStop> ();
timePoints = new ArrayList<Integer> ();
times = new ArrayList<Time> ();
timePointAmount = 0;
}
public Line (String n, Location dep, Location des, Time f, Time l, int p) {
name = n;
departure = dep;
destination = des;
first = f;
last = l;
period = p;
route = new ArrayList<BusStop> ();
timePoints = new ArrayList<Integer> ();
times = new ArrayList<Time> ();
timePointAmount = 0;
}
public void addNextBusStop (BusStop bs, int x) {
bs.addLine(this);
route.add (bs);
if(bs instanceof TimePoint) {
timePoints.add(x);
timePointAmount ++;
}
}
public void printSchedule (OutputStream o) throws IOException {
o.write(getSchedule().getBytes ());
}
public String getSchedule () {
String s = "SCHEDULE FOR LINE " + name + "\n";
for (int i = 0; i< route.size (); i ++) {
if (route.get(i) instanceof TimePoint) {
s += route.get(i).getName() + " ";
}
}
s += "\n";
while (first.compareTo(last) <= 0) {
int index = 0;
Time first1 = first.clone ();
for (int i = 0; i < route.size (); i ++) {
if (route.get(i) instanceof TimePoint) {
if (index == 0) {
s += first1 + " ";
Time x = first1.clone ();
times.add(x);
}
else
{
first1 = first1.advanceMinutes(timePoints.get (index));
times.add(first1);
s += first1 + " ";
}
index ++;
}
}
s += "\n";
first = first.advanceMinutes(period);
}
return s;
}
public void printRoute (OutputStream o) throws IOException {
o.write(getRoute ().getBytes ());
}
public String getRoute () {
String s = "ROUTE FOR LINE " + name + "\n";
for (int i = 0; i < route.size () - 1; i ++) {
s += route.get(i).getName () + ", ";
}
s += route.get(route.size () - 1).getName () + "\n";
return s;
}
}