-
Notifications
You must be signed in to change notification settings - Fork 0
/
Market.java
45 lines (35 loc) · 821 Bytes
/
Market.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
public class Market {
private Counter[] counters;
private int size;
public void setCounters(int size, int[] values){
counters = new Counter[size];
this.size= size;
for(int i=0; i<size; i++){
counters[i] = new Counter(i);
counters[i].setQuantity(values[i]);
}
}
public Counter getFreeCounter(){
for(int i=0; i<size; i++){
if(counters[i].isFree()){
return counters[i];
}
}
return null;
}
public boolean isExhausted(){
for(int i=0; i<size; i++){
if(!counters[i].isClose()){
return false; //Even if there's one counter that ain't
//closed yet, there's a possibility that the next element can be sent
//to it
}
}
return true; //All counters are closed
}
public void refresh(){
for(int i=0; i<size; i++){
counters[i].updateState();
}
}
}