Objectives: Define a constructor method that takes input Create and use a static variable...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Answer rating: 100% (QA)
Here is a modified version of the VotingMachine class according to the requirements provided Assignm... View the full answer
Related Book For
Data Structures and Algorithms in Java
ISBN: 978-1118771334
6th edition
Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Helium gas is throttled steadily from 500 kPa and 70C. Heat is lost from the helium in the amount of 2.5 kJ/kg to the surroundings at 25C and 100 kPa. If the entropy of the helium increases by 0.25...
-
Fill in the blanks. a. A is a quantitative variable whose value depends on chance. b. A discrete random variable is a random variable whose possible values .
-
Use the Product Rule or the Quotient Rule to find the derivative of the function. y = x 2 tan x
-
The following scenarios describe situations faced by hypothetical companies that currently have a centralized organization structure. As you review each of the scenarios, provide your opinion as to...
-
(Weighted-Average Number of Shares) Gogean Inc. uses a calendar year for financial reporting. The company is authorized to issue 9,000,000 shares of $10 par common stock . At no time has Gogean...
-
3. A region has the peak-period electricity demand in MWh given by D(r) = { 40,008 rif r 64 104,000 1,000r if r64 6 Exercises for Markets Module by Metin akanyldrm where r is the wholesale price in...
-
The soil mass in Figure P9-13 is loaded by a force transmitted through a circular footing as shown. Determine the stresses in the soil. Compare the values of r using an axisymmetric model with the ...
-
Suppose that the term structure of interest rates is flat in both Japan and the United States. The Japanese rate is 5% per annum and the US rate is 10% per annum (both with continuous compounding)....
-
Salma contributes $100 cash to her city's police department to be used as a reward for information about a crime. The city police department is a qualified organization, and her contribution is for a...
-
Below are three regression model that help predict the gross drug cost. Based on the R square, coefficients, t stat, and P-value, what model is the best in predicting the gross drug cost? Why? (For...
-
a) Fill in the table below and answer the following question Stock Date Bought Basis Date Sold Proceed Amount LT/ST realized Stock A 12/22/2018 5000 1/22/2023 1000 Stock B 1/11/2011 1000 1/11/2023...
-
You work as a finance manager for NSB, a large manufacturing company. You are part of a team tasked with reviewing the bonus scheme NSB operates for its managers. You have been asked to make a...
-
Previously voice revenue was the largest source of income for Telcom companies, now Voice and text are being replaced by internet messaging and VoIP. How do Telcom companies find additional sources...
-
Write a summary according to the articles and please be concise and give an overview of the articles in the summary. Try to answer quickly. It will be two-part. one is a summary another is the...
-
1A. If the researcher is concerned about the number of variables, the nature of the analysis, and completion rates, then, he/she is at which stage of the sampling design process (Figure 11.1 in the...
-
Implement a circular version of a doubly linked list, without any sentinels, that supports all the public behaviors of the original as well as two new update methods, rotate( ) and rotateBackward( ).
-
Describe an efficient greedy algorithm for making change for a specified value using a minimum number of coins, assuming there are four denominations of coins (called quarters, dimes, nickels, and...
-
Describe an efficient method for maintaining a favorites list L, with the move-tofront heuristic, such that elements that have not been accessed in the most recent n accesses are automatically purged...
-
You are to open the books of F. Polk, a trader, via the journal to record the assets and liabilities, and are then to record the dialy transactions for the month of May. A trial balance is to be...
-
Why do we have day books? Why don't we just enter every transaction directly into the appropriate ledger accounts?
-
Where is the other side of the double entry for all these expense postings to the ledgers recorded?
Study smarter with the SolutionInn App