Skip to content

haidarimahdi/Election_Simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Assignment 2: Election System Simulator

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.

Core Features

  • 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.

Skills & Concepts Demonstrated

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.

How to Compile and Run

To compile and run this project, you will need the Java Development Kit (JDK) installed on your system.

  1. Navigate to the src directory from your terminal:

    cd Election_Simulator/src
  2. Compile the Java source files. The following command will compile all .java files within the ueb package:

    javac ueb/*.java
  3. Run the application. Execute the main method from the src directory:

    java ueb.Main
  4. 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.

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages