Comp 152 Project 2
Due: Wednesday Feb 24th at
Summary and goals:
In this project you will have another chance to use ArrayLists since I got
several last minute emails saying several of
your were still shaky about them. You will also use UML to help
develop your project more
Write a program with three classes and the enum as seen in the UML diagram
This program will simulate the electoral college in the elections this
Party: This is an enumerated type
with three possible values (in alphabetical order): Democrat, Independent,
State: This class encapsulates a state in the electoral college.
It has three instance variables which should be initialized by the
three parameters to the constructors. The other three methods are all
accessors which retrieve the value of the associated instance variable.
ArrayList<State>: this is
the standard ArrayList in the Java.util package.
In the constructor
first create the stateVotes instance variable. Next open the file Electoral201X.txt
and read out the state names and the number of electoral votes for each
state. Use a java.util.Random object to assign the state to one of the
three parties for the Party Enum. Lets say that Democrats and
Republicans should each have a 2 in 5 chance of winning. The independent
should have a one in 5 chance of winning. Create the
resulting State object and store it in stateVotes. Do this for all 50
states (plus the district of Columbia).
In announceWinner() look through stateVotes and add up the total
electoral votes for each of the three parties. Print out the total
electoral votes for each party and if any party has more than the 270
needed to win, announce that party as the winner - otherwise announce
that Congress will have to make the choice. Finally, print the
individual winner of each state.
VoteTester: This class
contains only the main method. The main method should create an
ElectoralCollege object and then call announceWinner on that object.
You must have all of the methods and instance variables specified in
the UML. You may have any additional methods that you wish to make the
project easier to implement.
You also need to have a readme.txt file in your folder which contains
- your name
- a brief (one paragraph) description of how
you implemented the project, in particular, how did you decide to keep
- anything that is left undone in the project.
Include a readme.txt text file in your project. For this project the
readme.txt should include
- your name
- two or three sentences about which part of the project you had to do
the most trouble to complete
- Anything that is still not done when you submit.
When you are ready to submit your project zip up the folder with the java
code, the text input file and your readme and upload them to moodle.