-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRoster.java
More file actions
79 lines (67 loc) · 1.55 KB
/
Roster.java
File metadata and controls
79 lines (67 loc) · 1.55 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
/**
*Title: Roster
*Desription: A library of methods required to roster.
*Auther: James Sandford
*Last updated: 18/3/11
*Updated by: James Sandford
*Current state: Untested
*Known bugs: NONE
**/
import java.util.*;
class bus{
int busID;
int runTime;
public bus(int ID, int Time){
/**
*Takes the bus ID as the first argument and the time it has spent running
*in the past as the second.
*/
busID = ID;
runTime = Time;
}
public int getID(){
return busID;
}
public int getTime(){
return runTime;
}
}
public class Roster{
/**
*The main roster class. All interfaces to the roster library go here.
**/
List <bus> busList = new ArrayList<bus>();
public addBus(int ID, int Time){
/**
*Add a bus to the internal list.
**/
bus newBus = new bus(ID, Time);
busList.add(newBus);
Collections.sort(busList, bytime());
}
public int getBus(){
/**
*Get the next bus to be used and remove it from the internal list.
**/
bus nextBus = busList.get(0);
busList.remove(0);
return nextBus.getID();
}
public boolean delBus(int ID){
/**
*Remove bus from internal list. Returns true if item found and removed.
**/
for (int i = 0; i < busList.size(); i++){
if (busList[i].getID() == ID){
busList.remove(i);
return true;
}
}
return false;
}
private class byTime implements java.util.Comparator {
public int compare(bus first, bus second) {
return (first.getTime() - second.getTime());
}
}
}//class Roster