Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Could anyone please help me with this? package com.company; import java.util.*; class Door { boolean open; boolean hasGrandPrize; boolean chosenByContestant; } public class Game {
Could anyone please help me with this?
package com.company; import java.util.*; class Door { boolean open; boolean hasGrandPrize; boolean chosenByContestant; } public class Game { Door door1, door2, door3; void setUpGame() { door1 = new Door();door2 = new Door();door3 = new Door(); // initialize all the Door variables to false Random r = new Random(); int grandPrizeDoor = r.nextInt(3); switch(grandPrizeDoor) { case 0: door1.hasGrandPrize = true; break; case 1: door2.chosenByContestant = true;break; case 3: door3.chosenByContestant = true;break; } } void printStateOfDoors() { System.out.println("Door 1 is " + (door1.open ? " open, " : "not open, ") + (door1.hasGrandPrize ? "is the grand prize, and " : "is not the grand prize, and ") + (door1.chosenByContestant ? "is chosen." : "is not chosen.") ); System.out.println("Door 2 is " + (door2.open ? " open, " : "not open, ") + (door2.hasGrandPrize ? "is the grand prize, and " : "is not the grand prize, and ") + (door2.chosenByContestant ? "is chosen." : "is not chosen.") ); System.out.println("Door 3 is " + (door3.open ? " open, " : "not open, ") + (door3.hasGrandPrize ? "is the grand prize, and " : "is not the grand prize, and ") + (door3.chosenByContestant ? "is chosen." : "is not chosen.") ); } public class Game { Door door1, door2, door3; void setUpGame() { // shown earlier} door1 = new Door();door2 = new Door();door3 = new Door(); public void contestantChooseDoor(); Random r = new Random(); int contestantDoor = r.nextInt(3); switch(contestantDoor) { case 0: door1.chosenByContestant = true; break; case 1: door2.chosenByContestant = true; break; case 2: door3.chosenByContestant = true; break; } } } public class PlayManyGames { public static void main(String[] args) { Game theGame = new Game(); theGame.setUpGame(); theGame.printStateOfDoors(); theGame.contestantChooseDoor(); theGame.printStateOfDoors(); } } public static class Game { Door door1, door2, door3; public static Random r = new Random(); void setUpGame() { int grandPrizeDoor = r.nextInt(3); switch(grandPrizeDoor) { // etc. } public void contestantChooseDoor(); { int contestantDoor = r.nextInt(3); switch(contestantDoor) { // etc. } } import java.util.*; class Door { boolean open; boolean hasGrandPrize; boolean chosenByContestant; } public class main{ Door door1, door2, door3; void setUpGame() { door1 = new Door();door2 = new Door();door3 = new Door(); // initialize all the Door variables to false Random r = new Random(); int grandPrizeDoor = r.nextInt(3); switch(grandPrizeDoor) { case 0: door1.hasGrandPrize = true; break; case 1: door2.chosenByContestant = true;break; case 3: door3.chosenByContestant = true;break; } } void printStateOfDoors() { System.out.println("Door 1 is " + (door1.open ? " open, " : "not open, ") + (door1.hasGrandPrize ? "is the grand prize, and " : "is not the grand prize, and ") + (door1.chosenByContestant ? "is chosen." : "is not chosen.") ); System.out.println("Door 2 is " + (door2.open ? " open, " : "not open, ") + (door2.hasGrandPrize ? "is the grand prize, and " : "is not the grand prize, and ") + (door2.chosenByContestant ? "is chosen." : "is not chosen.") ); System.out.println("Door 3 is " + (door3.open ? " open, " : "not open, ") + (door3.hasGrandPrize ? "is the grand prize, and " : "is not the grand prize, and ") + (door3.chosenByContestant ? "is chosen." : "is not chosen.") ); } public static class Game { Door door1, door2, door3; void setUpGame() { // shown earlier} door1 = new Door(); door2 = new Door(); door3 = new Door(); void contestantChooseDoor () { Random r = new Random(); int contestantDoor = r.nextInt(3); switch (contestantDoor) { case 0: door1.chosenByContestant = true; break; case 1: door2.chosenByContestant = true; break; case 2: door3.chosenByContestant = true; break; } } } public static class PlayManyGames { public static void main(String[] args) { Game theGame = new Game(); theGame.setUpGame(); theGame.printStateOfDoors(); theGame.contestantChooseDoor(); theGame.printStateOfDoors(); } } public static class Game { Door door1, door2, door3; public static Random r = new Random(); void setUpGame() { int grandPrizeDoor = r.nextInt(3); switch (grandPrizeDoor) { // etc. } } void contestantChooseDoor() { int contestantDoor = r.nextInt(3); switch (contestantDoor) { // etc. } } }
I have this code for this problem, but It does not work
CSC 240 Computer Science III Homework 2 1. Finish the simulation program of the "Monty Hall paradox" that was discussed in class. Your program should ask the user if she wants to "always switch" or "never switch", and then silently simulate the game 10,000 times given this decision. Don't repeatedly ask the user for her decision on each triall Don't print out any debugging text/ Print out only the overall fraction of times the player wins the fabulous grang prize. CSC 240 Computer Science III Homework 2 1. Finish the simulation program of the "Monty Hall paradox" that was discussed in class. Your program should ask the user if she wants to "always switch" or "never switch", and then silently simulate the game 10,000 times given this decision. Don't repeatedly ask the user for her decision on each triall Don't print out any debugging text/ Print out only the overall fraction of times the player wins the fabulous grang prize
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