This Java command-line application simulates and compares two different election counting systems: First-Past-the-Post (FPTP) and Instant-Runoff Voting (IRV). It analyzes a predefined set of voting data to demonstrate how different electoral algorithms can lead to different outcomes from the same ballots.
- Dual Algorithm Analysis: Implements and contrasts two distinct voting methods on the same dataset.
- First-Past-the-Post (FPTP): Calculates the winner based on the highest number of first-preference votes.
- Instant-Runoff Voting (IRV): Implements a multi-round elimination process where the candidate with the fewest votes is removed and their votes are redistributed based on voters' next preferences until one candidate secures a majority (>50%).
- Interactive CLI: Allows the user to select a specific election dataset to analyze from the command line.
- Data Integrity: Ensures the original voting data is never altered by using deep copies for each simulation, making the analysis reliable.
This project showcases a variety of programming and software design concepts:
- Algorithm Design & Implementation: Logic for both FPTP and the more complex, iterative IRV system.
- Data Structures: Use of multi-dimensional arrays (
int[][][]) to effectively model complex, real-world data (ranked-choice voter preferences). - Object-Oriented Principles: Strong code modularity and encapsulation, with responsibilities separated into distinct classes (
Main,Election,Data,ArrayUtils). - Defensive Programming: Includes robust user input validation and ensures data immutability through deep copying.
- Unit Testing: The project includes a suite of JUnit tests to verify the correctness of utility functions and data handling.
To compile and run this project, you will need the Java Development Kit (JDK) installed on your system.
-
Navigate to the
srcdirectory from your terminal:cd Election_Simulator/src -
Compile the Java source files. The following command will compile all
.javafiles within theuebpackage:javac ueb/*.java -
Run the application. Execute the
mainmethod from thesrcdirectory:java ueb.Main
-
Interact with the program. The console will prompt you to enter an election ID (a number from 0 to 6) or -1 to quit. The results for both voting systems will be displayed for the chosen election.