-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimulate2.java
More file actions
43 lines (35 loc) · 1.16 KB
/
Simulate2.java
File metadata and controls
43 lines (35 loc) · 1.16 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
package cs2030.simulator;
import java.util.List;
import cs2030.util.PQ;
import cs2030.util.ImList;
public class Simulate2 {
private final PQ<Event> events;
private final Shop shop;
public Simulate2(int numServer, List<Double> arrivalTimes) {
ImList<Server> tempServe = ImList.<Server>of();
for (int i = 1; i <= numServer; i++) {
tempServe = tempServe.add(new Server(i));
}
this.shop = new Shop(tempServe);
PQ<Event> temp = new PQ<Event>(new EventComparator());
int i = 1;
for (double time : arrivalTimes) {
temp = temp.add(new EventStub(new Customer(i, time), time));
i++;
}
this.events = temp;
}
public String run() {
String results = "";
PQ<Event> running = this.events;
while (!running.isEmpty()) {
results += running.poll().first().toString() + "\n";
running = running.poll().second();
}
return results + "-- End of Simulation --";
}
@Override
public String toString() {
return String.format("Queue: %s; Shop: %s", events.toString(), shop.toString());
}
}