E-Voting System
E-Voting System
Semester –6th
Batch – I
Subject – Programming with Java
Subject code: OE-EC-604A
Faculty Name – SK. Hozayfa Rahman
Designation – Assistant Professor, CSE
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
• Java features like classes, encapsulation, static methods, and exception handling
3. System Design
The application is designed using the following classes:
Voter Class
Candidate Class
• Uses exception handling to catch invalid actions (like duplicate voting or wrongID).
4. Features Implemented
Feature Description
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.
Sample Output:
Available Candidates:
C1: Alice
C2: Bob
...
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.
// Voter class
class Voter {
this.voterId = voterId;
this.name = name;
this.hasVoted = false;
return voterId;
return hasVoted;
this.hasVoted = hasVoted;
// Candidate class
class Candidate {
this.candidateId = candidateId;
this.name = name;
this.votes = 0;
}
public String getCandidateId() {
return candidateId;
return name;
return votes;
votes++;
class ElectionCommission {
try {
if (voter == null) {
throw new Exception("Invalid voter ID.");
if (voter.hasVoted()) {
if (candidate == null) {
candidate.addVote();
voter.setHasVoted(true);
} catch (Exception e) {
return candidates.values();
// Main class
public class EVotingSystem {
// 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");
while (true) {
if (voterId.equalsIgnoreCase("exit")) {
break;
System.out.println("Available Candidates:");
ElectionCommission.castVote(voterId, candidateId);
}
ElectionCommission.showResults();
scanner.close();
Available Candidates:
C1: Alice
C2: Bob
Available Candidates:
C1: Alice
C2: Bob
Available Candidates:
C1: Alice
C2: Bob
Enter Candidate ID you want to vote for: C2
Available Candidates:
C1: Alice
C2: Bob