Question: Question 3 : ( 3 5 pts ) Problem: Voting system Write a Java program that simulates a simple voting system for an election. The

Question 3: (35 pts)
Problem: Voting system
Write a Java program that simulates a simple voting system for an election. The program should allow users to vote for one of several candidates, count the votes, and display the results.
The program should allow the following actions:
Vote for a Candidate: Users will vote for one of the predefined candidates.
Display Results: After a user decides to stop voting, the program should display the total votes for each candidate and declare the winner.
Exit: Users can exit the voting process at any time.
You should keep track of the total number of votes for each candidate. If a user enters an invalid candidate name, the program should display an error message and prompt them to try again. After voting ends, the program should display the number of votes for each candidate and the winner (the candidate with the most votes).
The program should have three candidates:
Alice
Bob
Charlie
The voting process should continue until the user types "exit". If an invalid candidate name is entered (i.e., not Alice, Bob, or Charlie), the program should display an error message and prompt the user to try again.Enter your vote (or type "exit" to finish): AliceEnter your vote (or type "exit" to finish): DaveInvalid candidate! Please enter a valid name (Alice, Bob, or Charlie).Enter your vote (or type "exit" to finish): exitVoting results:Alice: 1 voteBob: 0 votesCharlie: 0 votesWinner: Alice
Question 3 : ( 3 5 pts ) Problem: Voting system

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!