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 Voting Machine 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 o 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 voterlDs 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 voteForCandidate1 or voteForCandidate2. The argument sent to the voting methods is the voterID:
Honestly, I am struggling with my assignment here. I went to the teaching assistants and they told me that they still too are working through this problem. its harder to implement because I am a visual learner.
import java.util.Scanner;
public class Assignment03
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Voter ID List: ");
String voterId = keyboard.nextLine();
System.out.println("Total number of votes: ");
int totalVotes = keyboard.nextInt();
System.out.println("Votes for candidate 1: ");
int candidate1Votes = keyboard.nextInt();
System.out.println("Votes for candidate 2: ");
int candidate2Votes = keyboard.nextInt();
keyboard.close();
}
}



Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images









