-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicKitchen.java
More file actions
58 lines (43 loc) · 1.01 KB
/
Copy pathDynamicKitchen.java
File metadata and controls
58 lines (43 loc) · 1.01 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
package lab9;
import java.util.Queue;
import java.util.Random;
public class DynamicKitchen implements Runnable{
int mealStock = 175, mealRate = 6;
boolean underStock;
int guestsServed, income;
Queue<Guest> guestQ;
DynamicKitchen (Queue<Guest> guestQ) {
this.guestQ = guestQ;
}
@Override
public void run() {
//write your code here
Guest guest;
Random rand = new Random();
while (DynamicDiner.dinerOpen && !underStock) {
synchronized (guestQ) {
guest = guestQ.poll();
}
if (guest != null) {
guest.placeOrder();
if (guest instanceof Individual) {
mealStock-=1;
income+=mealRate;
}
else {
mealStock-=4;
income+=mealRate*4;
}
guestsServed++;
try {
Thread.sleep(rand.nextInt(20)+5);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (mealStock <=4)
underStock = true;
}
}
}