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