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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Step 1 Solution

Here this program might run by removing the public access specifier in the class Assignment03. 

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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education