-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatistic.java
More file actions
37 lines (30 loc) · 972 Bytes
/
Statistic.java
File metadata and controls
37 lines (30 loc) · 972 Bytes
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
package cs2030.simulator;
class Statistic {
private final double waitTime;
private final int numServed;
private final int numLeft;
Statistic() {
this.waitTime = 0;
this.numServed = 0;
this.numLeft = 0;
}
Statistic(double waitTime, int numServed, int numLeft) {
this.waitTime = waitTime;
this.numServed = numServed;
this.numLeft = numLeft;
}
public Statistic addServed() {
return new Statistic(this.waitTime, this.numServed + 1, this.numLeft);
}
public Statistic addLeft() {
return new Statistic(this.waitTime, this.numServed, this.numLeft + 1);
}
public Statistic addWait(double wait) {
return new Statistic(this.waitTime + wait, this.numServed, this.numLeft);
}
@Override
public String toString() {
return String.format("[%.3f %d %d]", this.waitTime / this.numServed,
this.numServed, this.numLeft);
}
}