Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In JDoodle, create a class called Assignment03. As always, put your Assignment number, name, and class section in a block comment at the beginning
In JDoodle, create a class called Assignment03. As always, put your Assignment number, name, and class section in a block comment at the beginning of your code. Assignments missing this information will not be graded. Write a VotingMachine class that: Accepts votes and voter IDs, one at a time, for each of two candidates Accumulates the number of votes for each of the two candidates Keeps track of voter IDs Reports out candidate votes and voter IDs Write another class with a main method that creates two instances of the Voting Machine, sends a sequence of votes and voter IDs to both instances, and then prints out a list of voter IDs, the total number of votes cast, and the vote totals for each of the two candidates. Details: The Voting Machine class should specify: Two private variables to keep track of the number of votes for two candidates. A private variable to keep a list of all the voter IDs. Two methods, one for each candidate, that: Accept a voterID as input Increment an internal vote counter for the candidate Concatenate the voterID to a string of voterIDs with the voterIDs separated by spaces. Use the String concat method to accomplish this. Two accessor methods, one for each candidate, that return the number of votes recorded for the candidate An accessor method that returns the voterIDs Be sure to comment your Voting Machine class and its methods appropriately such that javadoc could generate documentation. Your main method in Assignment03 should contain the following lines which cast votes for two candidates on two different voting machines. The voting machines are vm1 and vm2. The votes are cast by calling either voteForCandidate 1 or voteForCandidate 2. The argument sent to the voting methods is the voterID: //votes on the first voting machine vml.voteForCandidatel ("HL76983"); vm1.voteForCandidate 2 ("HL17522"); vml.voteForCandidatel ("HL32437"); vm1.voteForCandidatel ("HL02845"); vml.voteForCandidatel ("HL32710"); vm1.voteForCandidate 2 ("HL39835"); //Votes on the second voting machine vm2.voteForCandidate2 ("HL93952"); vm2.voteForCandidatel ("HL38385"); vm2.voteForCandidate 2 ("HL90310"); vm2.voteForCandidate 2 ("HL59293"); vm2.voteForCandidate 2 ("HL32346"); Before these lines, you need to create the two voting machine instances. (You might also declare any variables you use later.) After these lines, you need to write print statements (maybe mixed with others) to produce the following output: Voter ID List: HL76983 HL17522 HL32437 HL02845 HL32710 HL39835 HL93952 HL90310 HL59293 HL32346 HL38385 Total number of votes: 11 Votes for candidate 1: 5 Votes for candidate 2: 6 The values in the output must be generated by calling accessor methods on the voting machine instances. You can call the methods directly within the print statements or assign their values to variables and use the variables in the print statements.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Below is the implementation of the Assignment03 class and the VotingMachine class in Java java Assignment 03 Voting Machine Class Section Your class s...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started