-
Notifications
You must be signed in to change notification settings - Fork 0
/
RollerCoaster.jr
41 lines (33 loc) · 956 Bytes
/
RollerCoaster.jr
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
import java.util.*;
import edu.ucdavis.jr.*;
public class RollerCoaster {
public cap void() queue;
public cap void(String) go;
public Alarm alarm = null;
public Random r = new Random();
public int max = 10;
public RollerCoaster(){
this.queue = new op void();
this.go = new op void(String);
this.alarm = new Alarm(this.go);
}
public process runner{
String auth = null;
while (true) {
/* Generating a unique id for this alarm */
auth = Integer.toString(r.nextInt(10000));
this.alarm.set(auth);
inni void queue() st this.queue.length() == this.max {
this.serve();
} [] void go(String channel_auth) st channel_auth.equals(auth) && this.queue.length() > 0 {
System.out.println("The alarm went off!");
this.serve();
}
}
}
public void serve(){
while(this.queue.length() != 0) {
receive this.queue();
}
}
}