-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
61 lines (54 loc) · 1.83 KB
/
Main.java
File metadata and controls
61 lines (54 loc) · 1.83 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
59
60
61
package edu.wpi.voting;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import edu.wpi.voting.messages.StartElection;
import edu.wpi.voting.services.Management;
import edu.wpi.voting.services.Voter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Main {
enum Party {
Java("Java4Ever"),
Python("Pythonists"),
C("C-Lovers"),
NonProgrammers("Marketing People Party");
public final String partyName;
Party(String partyName) {
this.partyName = partyName;
}
}
public static void main(String[] args) {
final ActorSystem system = ActorSystem.create("VotingSystem");
List<Party> votes =
Arrays.asList(
Party.Java,
Party.Python,
Party.Python,
Party.C,
Party.Java,
Party.Java,
Party.NonProgrammers,
Party.NonProgrammers);
List<ActorRef> voters = new ArrayList<>();
for (Party vote: votes) {
voters.add(system.actorOf(Voter.props(vote.partyName)));
}
List<String> eligibleParties = new ArrayList<>();
for (Party party : Party.values()) {
if (!party.equals(Party.NonProgrammers)) {
eligibleParties.add(party.partyName);
}
}
ActorRef voteManager = system.actorOf(Management.props(eligibleParties, voters));
try {
voteManager.tell(new StartElection(), ActorRef.noSender());
System.out.println(">>> Press ENTER to exit <<<");
System.in.read();
} catch (IOException ioe) {
} finally {
system.terminate();
}
}
}