/VotingMachine.java:63: error: class Assignment03 is public, should be declared in a file named Assignment03.java public class Assignment03 {
public class VotingMachine {
// variable to store total votes for each candidate
private int totalVotesForCandidate1 = 0;
private int totalVotesForCandidate2 = 0;
// to keep record of voter IDs
private String voterIds = "";
/**
* This function will be used to simulate a voting for the first candidate
* @param voterId
*/
public void voteForCandidate1(String voterId) {
totalVotesForCandidate1++;
//voterIds .concat= voterId + "";
voterIds = voterIds.concat(voterId + " ");
}
/**
* This function will be used to simulate a voting for the second candidate
* @param voterId
*/
public void voteForCandidate2(String voterId) {
totalVotesForCandidate2++;
//voterIds .concat= voterId + "";
voterIds = voterIds.concat(voterId + " ");
}
/**
* This function will be used to get the total votes for the first candidate
*
* Returns:
* totalVotesForCandidate1 (int)
*/
public int getTotalVotesForCandidate1() {
return totalVotesForCandidate1;
}
/**
* This function will be used to get the total votes for the second candidate
* Returns:
* totalVotesForCandidate2 (int)
*/
public int getTotalVotesForCandidate2() {
return totalVotesForCandidate2;
}
/**
* This function will be used to get the total voter IDs stored in a string
*
* Returns:
* totalVotesForCandidate1 (int)
*/
public String getVoterIds() {
return voterIds;
}
}/*
* Assignment #:
* Name:
* Section:
*/
public class Assignment03 {
public static void main(String[] args) {
// creating the object of Voting Machine class
VotingMachine vm1 = new VotingMachine();
VotingMachine vm2 = new VotingMachine();
//votes on the first voting machine
vm1.voteForCandidate1("HL76983");
vm1.voteForCandidate2("HL17522");
vm1.voteForCandidate1("HL32437");
vm1.voteForCandidate1("HL02845");
vm1.voteForCandidate1("HL32710");
vm1.voteForCandidate2("HL39835");
//votes on the second voting machine
vm2.voteForCandidate2("HL93952");
vm2.voteForCandidate1("HL38385");
vm2.voteForCandidate2("HL90310");
vm2.voteForCandidate2("HL59293");
vm2.voteForCandidate2("HL32346");
int totalVotesForCandidate1 = vm1.getTotalVotesForCandidate1() + vm2.getTotalVotesForCandidate1();
int totalVotesForCandidate2 = vm1.getTotalVotesForCandidate2() + vm2.getTotalVotesForCandidate2();
int totalVotesProcessed = totalVotesForCandidate1 + totalVotesForCandidate2;
// printing the result
System.out.println("Voter ID List: " + vm1.getVoterIds() + vm2.getVoterIds());
System.out.println("Total number of votes: " + totalVotesProcessed);
System.out.println("Votes for candidate 1: " + totalVotesForCandidate1);
System.out.println("Votes for candidate 2: " + totalVotesForCandidate2);
}
}
Here this program might run by removing the public access specifier in the class Assignment03.
Step by step
Solved in 2 steps