Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

( Uses Java ) Background In the last activity, you created a Monty Hall Simulator that would ask the user for a door. The Monty

(Uses Java)
Background
In the last activity, you created a Monty Hall Simulator that would ask the user for a door. The Monty Hall Problem states that a contestant would increase their odds of winning if they
actually switched doors. In fact, their odds of winning go from 33% for not switching to 66% if you switch.
The math of this is much more confusing than it is to just simulate the results, so in this activity, you are going to create a simulator that can execute the Monty Hall Problem without user
input. From there, you can execute the simulator thousands of times and print out the results.
The Simulator
In this activity, you will create a method that will take whether or not a user will switch doors as an input and return whether or not they win. Specifically, the method should have this
header:
public static boolean runSim(boolean switchDoor)
Inside this method, you can use much of your work from the previous activity, but replace the user door selection with a random number for the door. Whether the user switches will be
based on the parameter passed in, but all other rules around opening the door and winning are the same as the previous exercise.
Running the Simulator
Once the simulator is available to run and return a result, you will want to simulate thousands of runs using a loop in the main method. This loop should count how many times the
contestant would win and then print out the results. Remember, we are expecting the user to win about 23 rd of the time when they switch and 13 rd of the time when they don't switch.
Sample Output:
Switch? false
33.33%
Switch? true
66.73%
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions