Question
Java program question. I have to implement an ElectionMachineVote class that can be used for an election. There has to be methods to clear the
Java program question.
I have to implement an ElectionMachineVote class that can be used for an election. There has to be methods to clear the machine state, to vote for Party1, and for Party2 and to get the number of votes for each one. I also have to write a program called VoteTest which tests the ElectionMachineVote class. It should do 3 separate elections with sample votes to show the ElectionMachineVote class that it works
I have two work in progress codes one for the "election" and one for the "test". However in the console all I am getting is
party 1 has won the election Its a tie! Party 2 has won the election
every time the test is run.
Could someone please help me
*Election code*
package votingMachine;
class VotingMachine
{ private int count_party1=0,count_party2=0; void clear() { count_party1=0;count_party2=0; } void vote_for_party1() { count_party1+=1; } void vote_for_party2() { count_party2+=1; } void result() { if(count_party1>count_party2) System.out.println("Party 1 has won the election"); else if(count_party1 *test code* package votingMachine; public class VotingMachineTest { public static void main(String args[]) { VotingMachine election1=new VotingMachine(); election1.clear(); election1.vote_for_party1(); election1.vote_for_party1(); election1.vote_for_party2(); election1.result(); VotingMachine election2=new VotingMachine(); election2.clear(); election2.vote_for_party1(); election2.vote_for_party2(); election2.result(); VotingMachine election3=new VotingMachine(); election3.clear(); election3.vote_for_party1(); election3.vote_for_party2(); election3.vote_for_party2(); election3.result(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started