A. Introduction

This is a well-known game, frequently shown on TV.

... Suppose you’re on a game show, and you’re given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what’s behind the doors, opens another door, say No. 3, which has a goat. He then says to you, “Do you want to pick door No. 2?” Is it to your advantage to switch your choice?

Ms. vos Savant proved that it is to your advantage, but many of her readers, including some mathematics professors, disagreed, arguing that the probability would not change because another door was opened.

B. Your project:

This is E6.22 in our textbook. It sounds like a lot but you might not have realized how much you have learnt. Give a try, don't worry if you could not make it work because it will be discussed in the next class.

C. Hints:

Use Math.random() to get a random number, but you need to research and figure out how to generate a random number between 1-3.

If looping 1000 times is too much to test, first try 10 times or even 5 times.

class Hall {

public static void main(String[] args) {

int SwitchWin = 0;

int StayWin = 0;

for(int i=1; i<=1000; i++){

int Car = (int) Math.floor(Math.random()*Math.floor(3)) + 1;

int Choice = (int) Math.floor(Math.random()*Math.floor(3)) + 1;

int RevealGoat = 0;

if(Car == Choice){

switch(Car){

case 1: RevealGoat = (int) Math.floor(Math.random()*Math.floor(2)) + 2; break;

case 2: RevealGoat = (int) Math.floor(Math.random()*Math.floor(2)) *2 +1; break;

case 3: RevealGoat = (int) Math.floor(Math.random()*Math.floor(2)) + 1; break;

}

}

else{

RevealGoat = 6 - (Car + Choice);

}

if(Car == Choice){

StayWin++;

}

if(Car == 6 - (RevealGoat + Choice)){

SwitchWin++;

}

}

System.out.println("Switching won " + SwitchWin + " times, and staying won " + StayWin);

}

}