-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServed.java
More file actions
43 lines (36 loc) · 1.25 KB
/
Served.java
File metadata and controls
43 lines (36 loc) · 1.25 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
class Served extends Event {
private static final int PRIORITY = 2;
private final int serverId;
Served(Shop shop, Customer customer, double time) {
super(shop, customer, time);
this.serverId = shop.getServerServingCustomer(customer);
}
Served(Shop shop, Customer customer, double time, int serverId) {
super(shop, customer, time);
this.serverId = serverId;
}
public int getPriority() {
return PRIORITY;
}
@Override
public int getServerId() {
return serverId;
}
@Override
public Event getNextEvent(Shop shop) {
Shop newShop = shop.servedCustomer(customer, time);
return new Done(newShop, customer, time + customer.getServiceTime(), serverId);
}
@Override
public ImList<Double> updateStatistics(ImList<Double> statistics) {
double numLeft = statistics.get(1) + 1;
double waitingTime = statistics.get(0) + (time - customer.getArrivalTime());
statistics = statistics.set(1, numLeft);
statistics = statistics.set(0, waitingTime);
return statistics;
}
@Override
public String toString() {
return String.format("%.3f ",this.time) + customer.toString() + " serves by " + serverId;
}
}