In this and the following assignment, you will implement the "instant runoff" voting system that is in use in national elections in Australia, some U.S. municipal elections such as San Francisco and Oakland, and a growing number of other places.
Instant runoff is designed to solve a common problem with regular "winner take all" voting. Consider this scenario:
In a traditional election, Jeb and Marco will be eliminated in the runoff even though all voters would find them acceptable. The two polarizing candidates, each of whom is despised by almost 75% of the voters, compete in the runoff, and one will be elected.
Politicians know this and are more likely to seek extreme positions in an election with more than two candidates.
In "instant runoff", voters get to rank their choices. If none of the candidates get the majority in the first round, the weakest candidate is eliminated. Votes for that candidate are redistributed, using the voter preferences for the remaining candidates.
In the scenario above, Jeb would be eliminated, his votes would be transferred to Marco, the second choice, and Marco would now rise to the top with 48.5% of the votes. Next, Ted would be eliminated, his votes would also go to Marco and he would win the election. And 100% of the voters would be ok with the outcome.
We will model the election with three classes: Candidate
, Ballot
, and
Election
. Your job is to complete each of them. In the first assignment, you complete Candidate
and Ballot
.