Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in Java Assignment Description: Write a program that will record the votes for one of two candidates by using the class VoteRecorder, which you will

in Java

Assignment Description: Write a program that will record the votes for one of two candidates by using the class VoteRecorder, which you will design and create. VoteRecorder will have static variables to keep track of the total votes for candidates and instance variables to keep track of the votes made by a single person. It will have the following attributes: nameCandidatePresident1 a static private string that holds the name of the first candidate for president nameCandidatePresident2 a static private string that holds the name of the second candidate for president nameCandidateVicePresident1 a static private string that holds the name of the first candidate for vice president nameCandidateVicePresident2 a static private string that holds the name of the second candidate for vice president votesCandidatePresident1 a static private integer that holds the number of votes for the first candidate for president votesCandidatePresident2 a static private integer that holds the number of votes for the second candidate for president votesCandidateVicePresident1 a static private integer that holds the number of votes for the first candidate for vice president votesCandidateVicePresident2 a static private integer that holds the number of votes for the second candidate for vice president myVoteForPresident a private integer that holds the vote of a single individual for president (0 for no choice, 1 for the first candidate, and 2 for the second candidate) myVoteForVicePresident a private integer that holds the vote of a single individual for vice president (0 for no choice, 1 for the first candidate, and 2 for the second candidate) In addition to appropriate constructors, VoteRecorder has the following methods: setCandidatesPresident(String name1, String name2) a static method that sets the names of the two candidates for president setCandidatesVicePresident(String name1, String name2) a static method that sets the names of the two candidates for vice president resetVotes a static method that resets the vote counts to zero getCurrentVotePresident a static method that returns a string with the current total number of votes for both presidential candidates getCurrentVoteVicePresident a static method that returns a string with the current total number of votes for both vice presidential candidates getAndConfirmVotes a nonstatic method that gets an individuals votes, confirms them, and then records them. getAVote(String name1, String name2) a private method that returns a vote choice for a single race from an individual (0 for no choice, 1 for the first candidate, and 2 for the second candidate) getVotes a private method that returns a vote choice for president and vice president from an individual confirmVotes a private method that displays a persons vote for president and vice president, asks whether the voter is happy with these choices, and returns true or false according to a yes or no response recordVotes a private method that will add an individuals votes to the appropriate static variables object for each voter. After all the voters are done, present the resultsVoteRecorder: Create a class, VoteRecorderDemo, that will conduct an election. The candidates for president are Annie and Bob. The candidates for vice president are John and Susan. Use a loop to record the votes of as many voters are available, no fixed or specific number. For voting, create a new VoteRecorder object for each voter. After all the voters are done, present the results.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions