-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tester3.java
180 lines (158 loc) · 4.21 KB
/
Tester3.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// Just to checker Exception cases
public class Tester3 {
static void pr(String n)
{
System.out.println(n);
}
public static void main(String[] args){
MMBurgers mm = new MMBurgers();
pr("\n--Started simulation Tester1--");
// Set number of counters and griddle capacity
try{
mm.setK(3);
mm.setM(6);
}
catch(IllegalNumberException e){
System.out.println(e);
}
try{
mm.setK(4);
}
catch(IllegalNumberException e){
System.out.println(e);
}
try{
mm.setM(5);
}
catch(IllegalNumberException e){
System.out.println(e);
}
// t = 0
pr("time t=0 before arrival of customers");
try{
// Query customer state
pr(""+mm.customerState(2, 1)); // 0
// Query griddle state
pr(""+mm.griddleState(1)); // 0
pr(""+mm.griddleWait(1)); // 0
}
catch(IllegalNumberException e){
System.out.println(e);
}
try {
System.out.println("\nt = 10\n");
mm.advanceTime(10);
}
catch (IllegalNumberException e) {
System.out.println(e);
}
// t = 1
pr("time t=1 [Back in time]");
try{
// Customer 1 coudln't arrive in time
mm.arriveCustomer(1, 0, 3);
}
catch(IllegalNumberException e){
System.out.println(e);
}
// t = 10
pr("time t=10");
try{
// Customer 1 arrives at 10
mm.arriveCustomer(1, 10, 3);
// Customer 2 arrives at 11
mm.arriveCustomer(2, 11, 4);
}
catch(IllegalNumberException e){
System.out.println(e);
}
// t = 1
pr("time t=1");
try{
// Query customer state
pr(""+mm.customerState(2, 1));
// Query griddle state
pr(""+mm.griddleState(1));
pr(""+mm.griddleWait(1));
}
catch(IllegalNumberException e){
System.out.println(e);
}
// t = 2
pr("time t=2");
try{
// Query griddle state
pr(""+mm.griddleState(2));
}
catch(IllegalNumberException e){
System.out.println(e);
}
// t = 3
pr("time t=3");
try{
// Query customer state
pr(""+mm.customerState(1, 3));
}
catch(IllegalNumberException e){
System.out.println(e);
}
// t = 7
pr("time t=7");
try{
// Query customer state
pr(""+mm.customerState(2, 7));
}
catch(IllegalNumberException e){
System.out.println(e);
}
// t = 10
pr("time t=10");
try{
// Query griddle wait time
pr(""+mm.griddleWait(10));
System.out.println("Customer Arrived!");
}
catch(IllegalNumberException e){
System.out.println(e);
}
// t = 14
pr("time t=14");
try{
// Query griddle state
pr(""+mm.griddleState(14));
}
catch(IllegalNumberException e){
System.out.println(e);
}
// t = 30
pr("time t=30");
try{
// Query griddle state
pr(""+mm.griddleState(30)); // 1
pr(""+mm.isEmpty()); // False
}
catch(IllegalNumberException e){
System.out.println(e);
}
// t = 31
pr("time t=31");
try{
// Advance time
mm.advanceTime(31);
pr(""+mm.isEmpty()); // True
}
catch(IllegalNumberException e){
System.out.println(e);
}
// End of simulation
pr("\n--End of simulation--");
// Query wait times
try{
System.out.println(mm.customerWaitTime(1)); // 12
System.out.println(mm.avgWaitTime()); // 12.0
}
catch(IllegalNumberException e){
System.out.println(e);
}
}
}