777 Simulating the Election Your program will run a series of simulations of the same election. Each simulation will be run as follows: 1. For each district: 1. Randomly determine how many people voted in this district. 2. Randomly determine what percentage of the vote our candidate received in this district. 3. Multiply these two values together to compute how many votes our candidate received in this district. 4. Add the number of votes our candidate received and the total number of votes cast in this district to the overall totals. 2. Compute the overall percentage of the vote our candidate received across all districts. 3. Print out the results (see below) 4. Add the turnout and votes earned in this simulation to the overall totals (see below) Your program should execute this entire procedure (including the output) for each simulation. After all simulations have been run, your program should all print out the average vote percentage our candidate received across all simulations. (If we've done things right, that should be pretty close to the polling average, though it won't exactly match.)

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

Running 5 simulations of 10 districts 

see the requirements on the image 

Simulating the Election
Your program will run a series of simulations of the same election. Each simulation will be run as follows:
1. For each district:
1. Randomly determine how many people voted in this district.
2. Randomly determine what percentage of the vote our candidate received in this district.
3. Multiply these two values together to compute how many votes our candidate received in this district.
4. Add the number of votes our candidate received and the total number of votes cast in this district to
the overall totals.
2. Compute the overall percentage of the vote our candidate received across all districts.
3. Print out the results (see below)
4. Add the turnout and votes earned in this simulation to the overall totals (see below)
Your program should execute this entire procedure (including the output) for each simulation. After all simulations
have been run, your program should all print out the average vote percentage our candidate received across all
simulations. (If we've done things right, that should be pretty close to the polling average, though it won't exactly
match.)
Transcribed Image Text:Simulating the Election Your program will run a series of simulations of the same election. Each simulation will be run as follows: 1. For each district: 1. Randomly determine how many people voted in this district. 2. Randomly determine what percentage of the vote our candidate received in this district. 3. Multiply these two values together to compute how many votes our candidate received in this district. 4. Add the number of votes our candidate received and the total number of votes cast in this district to the overall totals. 2. Compute the overall percentage of the vote our candidate received across all districts. 3. Print out the results (see below) 4. Add the turnout and votes earned in this simulation to the overall totals (see below) Your program should execute this entire procedure (including the output) for each simulation. After all simulations have been run, your program should all print out the average vote percentage our candidate received across all simulations. (If we've done things right, that should be pretty close to the polling average, though it won't exactly match.)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Thank you. With these two more requirements what should the codes be

Expand
Specification
↓
4
After computing the polling error, you should add this value to the polling average to determine the percentage of
woters our candidate received. Then, you can multiply this percentage by the previously generated turnout to
determine how many actual votes our candidate received.
Printing Results
After each simulation has been run, your program should print out some results:
1. Whether or not our candidate won the election.
o The candidate is considered to have won if they received more than half the votes.
2. The number and percentage of votes our candidate received, and the number and percentage of votes their
opponents received.
3. A visual representation of the votes.
Vote totals and vote percentages should simply be computed and printed. You do not need to attempt to round or
otherwise "prettify" the numbers-- just print out the values you compute in the format you see in the log above.
7.
Whether or not the candidate wins can be determined using a boolean expression that tests if the candidate
received at least half of the votes. You should directly print the result of this expression (which will be either true
or false)-- you should not attempt to print any different or custom messages (we have not learned how to do this
yet).
Transcribed Image Text:Expand Specification ↓ 4 After computing the polling error, you should add this value to the polling average to determine the percentage of woters our candidate received. Then, you can multiply this percentage by the previously generated turnout to determine how many actual votes our candidate received. Printing Results After each simulation has been run, your program should print out some results: 1. Whether or not our candidate won the election. o The candidate is considered to have won if they received more than half the votes. 2. The number and percentage of votes our candidate received, and the number and percentage of votes their opponents received. 3. A visual representation of the votes. Vote totals and vote percentages should simply be computed and printed. You do not need to attempt to round or otherwise "prettify" the numbers-- just print out the values you compute in the format you see in the log above. 7. Whether or not the candidate wins can be determined using a boolean expression that tests if the candidate received at least half of the votes. You should directly print the result of this expression (which will be either true or false)-- you should not attempt to print any different or custom messages (we have not learned how to do this yet).
Specification
The two ways we will use randomness are as follows:
Number of Voters (Turnout)
First, we will randomly determine the number of voters who cast votes in each district (known as turnout). This
value will be chosen randomly from a uniform distribution, meaning each possibility has an equal chance of being
chosen. Each district should have a randomly chosen number of voters between 1 and 1000 (inclusive). So,
there should be an equal chance of a district having 1000, 500, 256, 42, 9, 777, or any other number of voters
between 1 and 1000. You can generate this value using the nextInt () method of the Random() class in Java.
Vote Percentage (Poll Accuracy)
Second, we will randomly determine how accurate the polls were in each district. We will apply the margin of error
in our simulations by randomly determining an amount to add or subtract from the provided polling average for
each district. However, unlike the number of voters, we do not want to use a uniform distribution, as results close
to the polling average should be more likely than results that are off by a lot. Instead, we'll use a normal
distribution, which we can simulate using the nextGaussian () method in the Random class in Java. This method is
much like the nextInt () method we've been using but generates values in a different way.
To generate an appropriate random polling error, use the following expression:
nextGaussian () * 0.5 * POLL_ERR
Note that this expression will produce a double value; if you store the result in a variable, be sure it has the
correct type!
If you're curious about how this expression works, click Expand below. But it's also fine to just use the expression
as is.
► Expand
After computing the polling error, you should add this value to the polling average to determine the percentage of
voters our candidate received. Then, you can multiply this percentage by the previously generated turnout to
Transcribed Image Text:Specification The two ways we will use randomness are as follows: Number of Voters (Turnout) First, we will randomly determine the number of voters who cast votes in each district (known as turnout). This value will be chosen randomly from a uniform distribution, meaning each possibility has an equal chance of being chosen. Each district should have a randomly chosen number of voters between 1 and 1000 (inclusive). So, there should be an equal chance of a district having 1000, 500, 256, 42, 9, 777, or any other number of voters between 1 and 1000. You can generate this value using the nextInt () method of the Random() class in Java. Vote Percentage (Poll Accuracy) Second, we will randomly determine how accurate the polls were in each district. We will apply the margin of error in our simulations by randomly determining an amount to add or subtract from the provided polling average for each district. However, unlike the number of voters, we do not want to use a uniform distribution, as results close to the polling average should be more likely than results that are off by a lot. Instead, we'll use a normal distribution, which we can simulate using the nextGaussian () method in the Random class in Java. This method is much like the nextInt () method we've been using but generates values in a different way. To generate an appropriate random polling error, use the following expression: nextGaussian () * 0.5 * POLL_ERR Note that this expression will produce a double value; if you store the result in a variable, be sure it has the correct type! If you're curious about how this expression works, click Expand below. But it's also fine to just use the expression as is. ► Expand After computing the polling error, you should add this value to the polling average to determine the percentage of voters our candidate received. Then, you can multiply this percentage by the previously generated turnout to
Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

Thank you. But can u use Java to do it?

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Random Class and its operations
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
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