0% found this document useful (0 votes)
2 views10 pages

E-Voting System

The document presents a case study on a secure E-Voting System developed in Java, focusing on object-oriented programming principles. It outlines the system's design, including classes for voters, candidates, and the election commission, along with features such as encapsulation, exception handling, and one-time voting. The project aims to provide a user-friendly and secure electronic voting experience while ensuring data privacy and integrity.

Uploaded by

amankarn4321
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views10 pages

E-Voting System

The document presents a case study on a secure E-Voting System developed in Java, focusing on object-oriented programming principles. It outlines the system's design, including classes for voters, candidates, and the election commission, along with features such as encapsulation, exception handling, and one-time voting. The project aims to provide a user-friendly and secure electronic voting experience while ensuring data privacy and integrity.

Uploaded by

amankarn4321
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Dept.

of Electronics and Communication Engineering


Haldia Institute of Technology
2025

Case Study and Real Time Problem

Title: E-Voting System

Student Name-Anjali Kumari


Class Roll Number-22/ECE/040

Semester –6th
Batch – I
Subject – Programming with Java
Subject code: OE-EC-604A
Faculty Name – SK. Hozayfa Rahman
Designation – Assistant Professor, CSE

Session – EVEN SEM 2025


Case Study: Secure E-Voting System in Java

1. Introduction
In modern democracy, elections are vital for selecting leaders. With the growth of digital
technology, secure and reliable e-voting systems are needed to ensure transparency, reduce
fraud, and simplify the voting process. This project presents a console-based E-Voting
System developed using Java and following object-oriented programming principles.

2. Objective
The main objective of this project is to create a secure, interactive, and easy-to-use
electronic voting system using:

• Object-oriented programming

• Console-based user interaction

• Java features like classes, encapsulation, static methods, and exception handling

3. System Design
The application is designed using the following classes:

Voter Class

• Represents a registered voter.

• Fields: vote rid, name, has Voted (all private)

• Encapsulation: Uses getter/setter to protect data access

• Ensures a voter can vote only once

Candidate Class

• Represents a candidate standing for election.

• Fields: candidate, name, votes

• Maintains vote count for each candidate securely.


ElectionCommission Class

• Acts as the controller.

• Static methods for voter/candidate registration and vote processing.

• Uses exception handling to catch invalid actions (like duplicate voting or wrongID).

• Stores data in HashMaps for quick access.

Main Class (EVotingSystem)

• Handles user input via console.

• Allows voters to vote and view results.

• Loop continues until "exit" is entered.

4. Features Implemented

Feature Description

Encapsulation Private fields with getters/setters in Voter and Candidate classes

Static Methods In ElectionCommission to manage voting centrally

Access Specifiers private, public, and protected used appropriately

Prevents double voting, invalid IDs, and ensures voting


Exception Handling integrity

Voting Result Display Automatically tallies and displays votes at the end

5. Security Measures
• Authentication: Each voter must enter a valid voter ID.

• Vo ng Restriction: Each voter can vote only once, tracked by a hasVoted boolean.

• Error Handling: Exception handling ensures invalid inputs are safely handled.

• Data Privacy: Uses encapsulation to protect voter and candidate data.


6. User Input & Output
Inputs:

• Voter ID (e.g., V1, V2, etc.)

• Candidate ID (e.g., C1, C2, etc.)

Sample Output:

Enter your Voter ID (or type 'exit' to finish): V1

Available Candidates:

C1: Alice

C2: Bob

Enter Candidate ID you want to vote for: C1

Vote cast successfully!

...

--- Voting Results ---

Alice received 2 vote(s)

Bob received 1 vote(s)

7. Conclusion
This project demonstrates how to implement a secure, scalable, and user-friendly E-Voting
system using Java. It uses core object-oriented concepts and real-world logic to replicate
election processes. With features like authentication, one- me voting, and secure data
handling, it provides a simple yet effective simulation of real-world voting systems.

CODE OF THE GIVEN CASE STUDY: -


import java.util.*;

// Voter class

class Voter {

private String voterId;


private String name;

private boolean hasVoted;

public Voter(String voterId, String name) {

this.voterId = voterId;

this.name = name;

this.hasVoted = false;

public String getVoterId() {

return voterId;

public boolean hasVoted() {

return hasVoted;

public void setHasVoted(boolean hasVoted) {

this.hasVoted = hasVoted;

// Candidate class

class Candidate {

private String candidateId;

private String name;

private int votes;

public Candidate(String candidateId, String name) {

this.candidateId = candidateId;

this.name = name;

this.votes = 0;

}
public String getCandidateId() {

return candidateId;

public String getName() {

return name;

public int getVotes() {

return votes;

public void addVote() {

votes++;

// Election Commission class

class ElectionCommission {

private static Map<String, Voter> voters = new HashMap<>();

private static Map<String, Candidate> candidates = new HashMap<>();

public static void registerVoter(String voterId, String name) {

voters.put(voterId, new Voter(voterId, name));

public static void registerCandidate(String candidateId, String name) {

candidates.put(candidateId, new Candidate(candidateId, name));

public static void castVote(String voterId, String candidateId) {

try {

Voter voter = voters.get(voterId);

if (voter == null) {
throw new Exception("Invalid voter ID.");

if (voter.hasVoted()) {

throw new Exception("You have already voted.");

Candidate candidate = candidates.get(candidateId);

if (candidate == null) {

throw new Exception("Invalid candidate ID.");

candidate.addVote();

voter.setHasVoted(true);

System.out.println("Vote cast successfully!");

} catch (Exception e) {

System.out.println("Error: " + e.getMessage());

public static void showResults() {

System.out.println("\n--- Vo ng Results ---");

for (Candidate c : candidates.values()) {

System.out.println(c.getName() + " received " + c.getVotes() + " vote(s)");

public static Collection<Candidate> getCandidates() {

return candidates.values();

// Main class
public class EVotingSystem {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

// Registering Candidates

System.out.println("Registering Candidates...");

ElectionCommission.registerCandidate("C1", "Alice");

ElectionCommission.registerCandidate("C2", "Bob");

// Registering Voters

System.out.println("Registering Voters...");

ElectionCommission.registerVoter("V1", "John");

ElectionCommission.registerVoter("V2", "Emma");

ElectionCommission.registerVoter("V3", "Mike");

System.out.println("\n--- Welcome to the E-Voting System ---");

while (true) {

System.out.print("\nEnter your Voter ID (or type 'exit' to finish): ");

String voterId = scanner.nextLine();

if (voterId.equalsIgnoreCase("exit")) {

break;

System.out.println("Available Candidates:");

for (Candidate c : ElectionCommission.getCandidates()) {

System.out.println(c.getCandidateId() + ": " + c.getName());

System.out.print("Enter Candidate ID you want to vote for: ");

String candidateId = scanner.nextLine();

ElectionCommission.castVote(voterId, candidateId);

}
ElectionCommission.showResults();

scanner.close();

OUTPUT OF THE CODE: -

--- Welcome to the E-Voting System ---

Enter your Voter ID (or type 'exit' to finish): V1

Available Candidates:

C1: Alice

C2: Bob

Enter Candidate ID you want to vote for: C1

Vote cast successfully!

Enter your Voter ID (or type 'exit' to finish): V2

Available Candidates:

C1: Alice

C2: Bob

Enter Candidate ID you want to vote for: C2

Vote cast successfully!

Enter your Voter ID (or type 'exit' to finish): V1

Available Candidates:

C1: Alice

C2: Bob
Enter Candidate ID you want to vote for: C2

Error: You have already voted.

Enter your Voter ID (or type 'exit' to finish): V3

Available Candidates:

C1: Alice

C2: Bob

Enter Candidate ID you want to vote for: C1

Vote cast successfully!

Enter your Voter ID (or type 'exit' to finish): exit

--- Voting Results ---

Alice received 2 vote(s)

Bob received 1 vote(s)

You might also like