JMU logo

PA3: Fairly Odd Election (Decisions)

Odd parents characters
Photo credit Nickelodeon show The Fairly Odd Parents.

Part A - Readiness Quiz Due Tuesday, Oct 11 at 11:59 PM

Part B - Test cases Due Tuesday, Oct 11 at 11:59 PM

Part C - OddElection.java file Due: Friday, Oct 14 at 11:59 PM

Objectives

Instructions

Election season is upon us, and many people don't realize just how involved computers, algorithms, and network security are in this process. While we won't get into all the details here, you might check out the wikipedia article on electronic voting. Also of interest is the humanitarian open source software project Ushahidi which develops crowdsourcing tools and began in response to post-election violence in Kenya in 2008.

But on with our own election tools! The CS 149 election is certainly rigged -- and may become even more crazy. The leaders involved want to compare strategies and have asked you to implement several ballot counting approaches as outlined below. Some of them are "fairly odd".

You will implement these approaches in four separate methods in a class called OddElection. Each method will be passed three parameters and will return an integer corresponding to the winner of the election. You will also need to write JUnit tests that "cover" (execute) 100% of your statements. See OddElectionTest for examples.

In addition, your counting methods should check the values of the parameters to make sure that they are reasonable (not negative). Invalid election parameters should cause your counting methods to return -1. Don't forget to test these cases too!

Getting Started

The following source files are povided as a starting point:

JUnit is the way to "run" this assignment. However, you may refer to OddElectionDriver which illustrates how your methods might be used in a main application.

As you work on the assignment, you may find it useful to reuse existing methods and/or implement additional methods to simplify your code. Feel free to add new methods to OddElection, but do NOT change the design of any of the provided methods.

Counting Approaches

  1. Popular vote - the candidate with the highest number of votes wins, and ties result in an invalid election.

  2. Absolute majority - the candidate with the highest number of votes wins, but only if the number of votes is at least 50% of all votes cast in the election. If the highest number of votes is not a majority or there is a tie, the election is invalid.

  3. Odd - all candidates with an "odd" number of votes get their vote count doubled, unless the count ends with the digit 5. Once all vote counts are manipulated, the winner is determined by popular vote.

  4. Even Odder - all candidates with an even number of votes gets their vote count doubled, unless the count ends in a 4, in which case 10 is subtracted from the vote count. Once all vote counts are manipulated, the winner is determined by popular vote.

Submission

Part B - Submit your OddElectionTest.java file via Web-CAT

Part C - Submit your  OddElection.java and OddElectionTest.java into a zip file, and submit via Web-CAT. Do not include OddElectionDriver.java or any other files in your zip archive. There will be no Canvas submission for this assignment.

Both your files must conform to the CS 149 Style Guide. Don't forget to run Checkstyle before your final submission. For this assignment, pay special attention to the indentation rules. All blocks of code (even if one line) should be surrounded by curly braces.

Honor Code

This assignment must be completed individually. Your submission must conform to the JMU Honor Code. Authorized help is limited to general discussion on Piazza, the lab assistants assigned to CS 139/149, and the instructor. Copying work from another student or the Internet is an honor code violation and will be grounds for a reduced or failing grade in the course.


Contact chaoaj[at]jmu.edu for more information about this page or Twitter: @chaoaj