Question: JAVA PROGRAMMING Implement a VotingMachine class that can be used for a simple election. A voting machine has two properties- republican votes and democrat votes

JAVA PROGRAMMING

Implement a VotingMachine class that can be used for a simple election.

  • A voting machine has two properties- republican votes and democrat votes
  • Write a constructor that accepts no arguments and sets the votes for both parties to 0
  • Write methods (note that none of these methods take any arguments or return any values)
    • void clear() to reset the votes for each party to 0
    • void voteDem() that increases the democrat votes by 1
    • void voteRep() that increases the republican votes by 1
    • void printVotes() that prints the tallies of the votes for both parties in this way:

Republican Votes: 6

Democrat Votes: 10

  • Identify the accessor methods (access/read/gets properties) and mutator methods (change/modify/sets properties)
  • Test your class: Create a voting machine object called vm1. Then vote for each party multiple times by calling the voteDem and voteRep methods multiple times and then print the votes received by each party by using the printVotes method. Then clear the votes by using the clear method and reprint the votes of each party.

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!