Answered step by step
Verified Expert Solution
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 for not switching to 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 runSimboolean 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 rd of the time when they switch and rd of the time when they don't switch.
Sample Output:
Switch? false
Switch? true
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started