/VotingMachine.java:63: error: class Assignment03 is public, should be declared in a file named Assignment03.java public class Assignment03 {

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter4: More Object Concepts
Section: Chapter Questions
Problem 5RQ
icon
Related questions
Question

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);
    }
}

/VotingMachine.java:63: error: class Assignment03 is public, should be declared in a file named Assignment03.java
public class AssignmentØ3 {
1 error
Transcribed Image Text:/VotingMachine.java:63: error: class Assignment03 is public, should be declared in a file named Assignment03.java public class AssignmentØ3 { 1 error
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT