Presentation is loading. Please wait.

Presentation is loading. Please wait.

ELECTION NIGHT CITS1001. Example development Understanding the problem Understanding the solution Structuring the solution Implementing the solution (Testing.

Similar presentations


Presentation on theme: "ELECTION NIGHT CITS1001. Example development Understanding the problem Understanding the solution Structuring the solution Implementing the solution (Testing."— Presentation transcript:

1 ELECTION NIGHT CITS1001

2 Example development Understanding the problem Understanding the solution Structuring the solution Implementing the solution (Testing the solution) 2

3 Preferential voting An election has M candidates (we will use five candidates ABCDE in examples) N formal votes One winner, who needs N/2+1 votes to triumph Each voter returns a list of preferences for all candidates e.g. CAEDB But not CAE or CAEDA or CAXEDB or … http://www.aec.gov.au/Voting/counting/hor_count.htm 3

4 The count Discard informal votes Allocate each formal vote to its first preference candidate Then in each round of the count If the leading candidate has enough votes, Declare them the winner Otherwise, Identify the candidate X with the fewest votes Redistribute each of X’s votes to its highest-ranked surviving candidate Eliminate X 4

5 An example 100 votes: 12 informal, and 88 formal 88/2+1 votes = 45 required to win After the initial distribution A 11, B 14, C 29, D 25, E 9 No winner yet, so E is eliminated in Round 1 e.g. vote EABDC would be transferred to A A 17, B 16, C 29, D 26 No winner yet, so B is eliminated in Round 2 e.g. vote BEDAC would be transferred to D A 22, C 31, D 35 No winner yet, so A is eliminated in Round 3 C 47, D 41 C has enough votes to be declared the winner 5

6 What types of entities do we have? Votes Each vote is an expression of a voter’s preferences Candidates Each candidate collects votes until they either win or are eliminated Elections Each election represents one constituency 6

7 The Vote class What is the state of a Vote? The list of preferences for surviving candidates What inputs does the constructor need? The voter’s original list of preferences What accessor methods do Votes provide? Who the Vote is currently for: public char getFirstPreference(String losers) What other methods do Votes provide? A test for whether the Vote is formal: public boolean isFormal(String candidates) 7

8 The Candidate class What is the state of a Candidate? Their name, and their current pile of Votes What inputs does the constructor need? Their name What accessor methods do Candidates provide? getName(), getVotes(), getCount() What other methods do Candidates provide? A way of adding votes to the pile: public void addVotes(ArrayList vs, String losers) A test for whether the candidate has won: public boolean isWinner(int noOfVotes) 8

9 The Election class What is the state of an Election? A pile of Votes for each surviving Candidate What inputs does the constructor need? Where to get the voting papers and the candidates’ names from What accessor methods do Elections provide? None – “top-level” class Although there could be a higher class with a collection of Elections What other methods do Elections provide? The constructor could do the initial distribution A method to perform one round of the count Probably several private methods to structure the code 9

10 Implementation – Class Diagram 10

11 Implementation questions – Vote What type should the list of preferences be? If the candidates’ names are just one char each, a simple String will do Otherwise a String[] or an ArrayList, depending on… Should we delete the names of eliminated candidates, or just ignore them? We could ignore them when looking for the next preference We could delete them as needed We could delete all mentions of c at the time they are eliminated 11

12 Implementation questions – Candidate What type should the pile of Votes be? For most candidates, the pile will grow during the count So an ArrayList is best 12

13 Implementation questions – Election What type should the pile of Candidates be? Again, an ArrayList is best Should we delete eliminated Candidates, or just ignore them? We can use multiple constructors for testing: public Election(String candidates, String votes) {…} public Election(String votes) {this(“candidates.txt”, votes);} public Election() {this(“votes.txt”);} 13


Download ppt "ELECTION NIGHT CITS1001. Example development Understanding the problem Understanding the solution Structuring the solution Implementing the solution (Testing."

Similar presentations


Ads by Google