- Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathVote.java
35 lines (28 loc) · 975 Bytes
/
Vote.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
packageelections;
importjava.util.Random;
importjava.util.Vector;
publicclassVoteextendsThread {
Randomrand = newRandom(); // generating a random number
intmax = 750; // max wait time for thread
intmin = 100; // min wait time for thread
intv, s;
Vectorvec;
publicVote(intv, Vectorvec) {
this.v = v;
this.vec = vec;
}
publicvoidrun() {
try {
// while voting print id
while (vec.size() < 240) { // ensure size of vote vector is below 240
System.out.println(this.getName() + " is Voting");
vec.add(v);
s = rand.nextInt((max - min) + 1) + min;
System.out.println(this.getName() + " is sleeping for " + s);
Thread.sleep(s); // create random delay between threads
}
} catch (InterruptedExceptione) {
System.out.println("Voting Exception: " + e);
}
}
}