Add a class called VotingMaching that contains: § A democratVotes of int type that defines the number of votes the Democrat candidate received. § A republicanVotes of int that defines the number of votes the Republican candidate received. § A no-arg constructor that set all candidates' tallies at zero, § The accessor methods (getters) for all data fields. § The method castDemocratVote(), which casts a single vote for the Democrat candidate. § The method castRepublicanVote(), which casts a single vote for the Republican candidate. § The method stuffDemocratBallot()that takes a numVotes of int, which increase the democratVotes by numVotes votes for the Democrat. 2 of 3 § The method stuffRepublicanBallot()that takes a numVotes of int, which increase the republicanVotes by numVotes votes for the Republican, § A getTotalVotes() that returns the total number of votes cast in the race. § A getDemocratVotePercentage() that returns the percentage of votes cast for the Democrat candidate. § A getRepublicanVotePercentage() that returns the percentage of votes cast for the Republican candidate in java

Respuesta :

The Java code is given below:

Java Code

VotingMachine vm = new VotingMachine();

vm.voteDemocrat();

vm.voteDemocrat();

vm.voteRepublican();

vm.voteIndependent();

vm.countDemocrat(); // returns 2

vm.countRepublican(); // returns 1

vm.countIndependent(); // returns 1

vm.whoWon(); // returns “Democrat”

The VotingMachine class remembers and counts votes in a simple election with only parties, democrats and republicans.

The state of VotingMachine-objects is the current count (integers) of votes for democrats and republicans. In the initial state, both counters should be zero.

The VotingMachine class has two method for reading the current state, getDemocratTally() and getRepublicanTally(), and three methods for altering the state, clear(), voteDemocrat() and voteRepublican(), with the following behavior:

getDemocratTally - returns the current number (an int) of democrat votes

getRepublicanTally - returns the current number (an int) of republican votes

voteDemocrat() - registers a(nother) democrat vote

voteRepublican() - registers a(nother) republican vote

clear - clears all the votes and returns to the initial state

Read more about java programming here:

https://brainly.com/question/18554491

#SPJ1