-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModerator.java
54 lines (46 loc) · 1.14 KB
/
Moderator.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
46
47
48
49
50
51
52
53
54
import java.util.*;
public class Moderator implements Runnable
{
public static Moderator instance;
private static SharedData obj;
private int numberGenerated=0;
/*public Moderator(SharedData obj)
{
this.obj=obj;
}*/
private Moderator(SharedData obj)
{
Moderator.obj=obj;
}
public static Moderator getInstance(SharedData obj)
{
if(instance==null)
{
instance=new Moderator(obj);
}
return instance;
}
public void run()
{
System.out.println("MODERATOR STARTED");
while(!obj.gameCompleteFlag && obj.al.size()<10)
{
Random num=new Random();
this.numberGenerated=num.nextInt(50)+1;
obj.put(this.numberGenerated);
//System.out.println();
System.out.println("Moderator has generated " + this.numberGenerated);
try {
Thread.sleep(1000);
// System.out.println("wait");
} catch (InterruptedException e) {
// System.out.println("we have error");
}
}
if(obj.gameCompleteFlag==false)
{
System.out.println();
System.out.println("Unfortunately,no one has won :(");
}
}
}