Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objectives: Define a constructor method that takes input Create and use a static variable Create and use a static method Write and call the

imageimage

Objectives: Define a constructor method that takes input Create and use a static variable Create and use a static method Write and call the toString() method for a class Details: In JDoodle, create a class called Assignment04. 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. In this assignment, you will get the entire main method and you must use it as written. The main method is at: https://www.jdoodle.com/ia/vvl. Copy this to your own workspace, and then you will need to add the Voting Machine class you have already created and modify it. Modify the Voting Machine class that you wrote last week (if you messed up last week, this is your chance to fix your Voting Machine class). It should still work like before, but add the following: A private static variable that keeps a count of the number of voting machines created. A constructor method should increment this variable with each new instance (see the constructor method bullet point below). A public static method that returns the value of the voting machine count. A private static variable that keeps track of the number of votes cast across all machines. This variable should be incremented each time a vote is cast in any instance. A public static method that returns the value of the number of votes cast across all machines. A constructor method that takes the name of a voting district (a city) as an input parameter. The constructor method should: Assign the name of the voting district to a private instance variable. o keep track of how many voting machine instances are being created by incrementing a static variable each time a new voting machine is instantiated. Use the static variable that counts voting machine instances to assign a sequence number to each voting machine such that the first one created is number 1, the second one is number 2, and so on. A toString() method that creates a string that can be printed as in the example below. Here is the expected output from the main method once you have successfully added and modified the Voting Machine class: Number of voting machines: 0 Total number of votes cast: 0 Creating voting machines. Number of voting machines: 3 Total number of votes cast: 0 Casting votes... Voting machine 1 done. Voting machine 2 done. Voting machine 3 done. All done. Report: Voting Machine: 1 Voting District: Kailua Number of votes for candidate 1: 2 Number of votes for candidate 2: 1 Voter list: HL76983 HL17522 HL32437 Voting Machine: 2 Voting District: Kapolei Number of votes for candidate 1: 1 Number of votes for candidate 2: 4 Voter list: HL93952 HL90310 HL59293 HL32346 HL38385 Voting Machine: 3 Voting District: Honolulu Number of votes for candidate 1: 2 Number of votes for candidate 2: 1 Voter list: HL02845 HL32710 HL39835 Number of voting machines: 3 Total number of votes cast: 11 The values printed from each voting machine must come from instance variables. Notice that the total number of votes cast has changed from the first time it is printed to the next time. You should make this happen by incrementing a static variable each time a vote is cast on any machine.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Here is a modified version of the VotingMachine class according to the requirements provided Assignm... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Structures and Algorithms in Java

Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser

6th edition

1118771334, 1118771338, 978-1118771334

Students also viewed these Programming questions

Question

Explain possible uses for single-case research.

Answered: 1 week ago