-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildingFloor.java
99 lines (72 loc) · 2.11 KB
/
BuildingFloor.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
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
// Melody Wang 59907761
// Tianran Zhang 37914655
public class BuildingFloor {
//local variable
private int[] totalDestinationRequests;
int[] arrivedPassengers;
int[] passengerRequests;
int approachingElevator;
//constructor
public BuildingFloor(){
this.totalDestinationRequests = new int[5];
this.arrivedPassengers = new int[5];
this.passengerRequests = new int[5];
this.approachingElevator = -1;
}
//setter
public void updateTotalDestinationRequests(int floor, int passengers){
this.totalDestinationRequests[floor] += passengers;
}
public void setArrivedPassengers(int floor, int passengers){
this.arrivedPassengers[floor] += passengers;
}
public void setPassengerRequests(int floor, int passengers){
this.passengerRequests[floor] = passengers;
}
public void setApproachingElevator(int elevatorID){
this.approachingElevator = elevatorID;
}
//getter
public int[] getTotalDestinationRequests(){
return totalDestinationRequests;
}
public int[] getArrivedPassengers(){
return arrivedPassengers;
}
public int[] getPassengerRequests(){
return passengerRequests;
}
public int getApproachingElevator(){
return approachingElevator;
}
//update the floor info when there are new PassengerArrival
//used in the BuildingManager
public void setPassengerArrival(int numPassengers, int dest) {
updateTotalDestinationRequests(dest, numPassengers);
setPassengerRequests(dest, numPassengers);
}
//sum up the total number of passengers requesting elevator access on this floor
public int sumOfTotalRequests(){
int sum = 0;
for (int i = 0; i < 5; i++){
sum += this.getTotalDestinationRequests()[i];
}
return sum;
}
//sum up the total number of passengers that exited an elevator on the floor
public int sumOfArrival(){
int sum = 0;
for (int i = 0; i < 5; i++){
sum += this.getArrivedPassengers()[i];
}
return sum;
}
//sum up the total number of passengers currently requesting elevator access on this floor
public int sumOfRequests(){
int sum = 0;
for (int i = 0; i < 5; i++){
sum += this.getPassengerRequests()[i];
}
return sum;
}
}