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

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 Databases Questions!