-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBus.java
More file actions
75 lines (63 loc) · 1.74 KB
/
Bus.java
File metadata and controls
75 lines (63 loc) · 1.74 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
import java.util.*;
import java.lang.*;
// inspired by Ferry class in Lab 10
public class Bus {
private ArrayList<Rider>lst = new ArrayList<Rider>();
private double arrivalTime;
private int max = 50; // holds 50 passengers max
private boolean express;
public int totalPassengersBoarded;
public Stat myStats;
private int number; // out of all the buses, what number bus is this?
public double averageCapacity;
public double oldCapacity;
public double lastCapacityUpdateTime;
public Bus(boolean ex, int num){
this.express = ex;
this.number = num;
}
public boolean addRider(Rider r){
if (lst.size() < max){
lst.add(r);
totalPassengersBoarded++;
// this.stats.updateCapacityStats(BusSim.agenda.getCurrentTime(),
// this.getCurrentNumOfPassengers());
return true;
} return false;
}
public Rider[] removeRidersAtStop(int stopNum){
Rider[] dummy = new Rider[50];
int index = 0;
for (int i = 0; i < this.lst.size(); i++){
if ((lst.get(i)).getDestination() == stopNum){
dummy[index] = lst.get(i);
index++;
lst.remove(i);
}
}
int cutoff = index;
// now copy over all non-null elements to non-dummy array
Rider[] removed = new Rider[cutoff];
System.arraycopy(dummy, 0, removed, 0, cutoff);
return removed;
}
public boolean isFull(){
return (this.lst.size() == this.max);
}
public boolean isExpress(){
return this.express;
}
public void setArrivalTime(double t){
this.arrivalTime = t;
}
public int getNumber(){
return this.number;
}
public Stat getStats(){
return this.myStats;
}
public int getCurrentNumOfPassengers(){
// how many passengers are currently on the bus
return this.lst.size();
}
} // Bus