-
Notifications
You must be signed in to change notification settings - Fork 2
/
ElevatorCarPanel.java
65 lines (50 loc) · 1.44 KB
/
ElevatorCarPanel.java
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
package Undergraduate_Project;
import java.util.*;
public class ElevatorCarPanel {
////////// Variables //////////
private boolean emergencyMode;
private boolean maintenanceMode;
// private Vector<Integer> destinationFloor = new Vector<>();
private LinkedList<Integer> destinationFloor;
////////// Accessors //////////
public boolean getEmergencyMode() {
return emergencyMode;
}
public boolean getMaintenanceMode() {
return maintenanceMode;
}
////////// Mutators //////////
public void setEmergencyMode(boolean state){
emergencyMode = state;
}
public void setMaintenanceMode(boolean state) {
maintenanceMode = state;
}
////////// Constructor //////////
ElevatorCarPanel() {
emergencyMode = false;
maintenanceMode = false;
destinationFloor = new LinkedList<Integer>();
}
////////// Methods //////////
// This method adds the parameter n to the end of the linked list
// and returns the first element of the list. If n not a valid input
// then it returns -1
public int addFloorNToDistinationFloor(int n) {
if (n >= 5) {
return -1;
} else {
destinationFloor.push(n);
return destinationFloor.peekFirst();
}
}
// If a button bas been pressed returs the first number of the first
// button pressed. If no buttons have been pressed returns -1;
public int getNextFloor() {
if (destinationFloor.peek() == null) {
return -1;
} else {
return destinationFloor.pop();
}
}
}