Repository navigation
Expand file tree
/
Copy pathServiceDevice.java
More file actions
111 lines (83 loc) · 2.54 KB
/
Copy pathServiceDevice.java
File metadata and controls
111 lines (83 loc) · 2.54 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
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
import helpers.RandomNumberGenerator;
public class ServiceDevice {
private int avgServiceTime;
private int currServiceTime;
private int busyTime;
private boolean isBusy;
private int currAgentTime;
private int agentsServed;
private int totalWaitTime;
private int maxWaitTime;
private ServiceDevice() {
this.currServiceTime = 0;
this.busyTime = 0;
this.isBusy = false;
this.currAgentTime = 0;
this.totalWaitTime = 0;
this.maxWaitTime = 0;
this.agentsServed = 0;
}
public ServiceDevice(int avgServiceTime) {
this();
this.avgServiceTime = avgServiceTime;
}
public void nextAgent(AgentsQueue agentsQueue) {
if (agentsQueue.hasFreeSpace()) {
Agent nextAgent = agentsQueue.removeAgent();
this.setCurrServiceTime();
this.currAgentTime = 0;
this.isBusy = true;
this.totalWaitTime += nextAgent.getCurrWaitTime();
if (nextAgent.getCurrWaitTime() > this.maxWaitTime) {
this.maxWaitTime = nextAgent.getCurrWaitTime();
}
}
}
public void serveAgent() throws UnsupportedOperationException {
if (isBusy) {
this.currAgentTime++;
this.busyTime++;
if (this.currAgentTime == this.currServiceTime) {
this.isBusy = false;
agentsServed++;
}
} else {
throw new UnsupportedOperationException();
}
}
public int getAvgServiceTime() {
return avgServiceTime;
}
public int getCurrServiceTime() {
return currServiceTime;
}
private void setCurrServiceTime() {
RandomNumberGenerator randomNumberGenerator = new RandomNumberGenerator();
this.currServiceTime = randomNumberGenerator.gerRandomNumberBasedOnAverage(avgServiceTime);
// System.out.println("service time: " + this.currServiceTime);
}
public int getBusyTime() {
return busyTime;
}
public boolean isBusy() {
return isBusy;
}
public void setBusy(boolean busy) {
isBusy = busy;
}
public int getCurrAgentTime() {
return currAgentTime;
}
public void setCurrAgentTime(int currAgentTime) {
this.currAgentTime = currAgentTime;
}
public int getTotalWaitTime() {
return totalWaitTime;
}
public int getMaxWaitTime() {
return maxWaitTime;
}
public int getAgentsServed() {
return agentsServed;
}
}