Introduction to Computer Science I

Project 1


Let's Make a Deal!

Way back in the 1970's, there was a goofy television game show know as, Let's Make a Deal. As a member of the audience, you were expected to dress in a manner that sacrified as much dignity as possible, thus gaining the attention of the host who would select you as a participant. Once selected by the host, here's how the game worked:

  1. On stage would be three doors, all initially closed. You would then be told that behind one of those doors there was a tremendous prize -- a new car, a big vacaation, a pile of gold bullion, etc. Behind the other two doors were wholly undesirable prize items, such as a goat, some toilet paper, and so on.
  2. The host, Monty Hall, would ask you behind which door the prize could be found. You had to guess door number 1, 2, or 3. Let's say, as an example, that you picked door number 2.
  3. Monty Hall would then open one of the door that you did not guess. That is, he would show either door 1 or 3 -- let's say, for argument's sake, that he shows you door 3. Behind this door is one of the dud "prizes".
  4. Finally, Monty Hall would give you one more chance. You could either stay with your original door choice (e.g., door 2), or you could switch to the one remaining closed door that you did not choose (e.g., door 1). Once you make that select (stay or switch), you get to find out whether you won the real prize.

The big question: If you were a contestant on the show, then, when you reached the final step, would you elect to switch or to stay? Probabilistically, does it matter?

We could try to use our brains to reason out the answer to this question, but why do that when you can have the computer play the game thousands of times, keeping track of whether you should have switched or stayed? That is what we will do...


Your assignment

Write a program, named MakeADeal, that simulates the playing of this game. Specifically, it should:

  1. Randomly select the door that contains the real prize.
  2. Randomly select the initial door guessed by the player.
  3. Randomly select a door to show the player that has a dud prize (it must be neither the door hiding the real prize not the door originally guessed by the player).
  4. Determine which strategy would win at this point -- switching or staying.

At the beginning of the program, the user should be prompted to enter the number of repetitions of the game that should be simulated, known as the number of trials. Once that value (a positive integer) is provided, the above set of steps should be performed that many times. With each iteration of the game, the program should sum the number of times that switching would have won and the number of times staying would have won.

The program should, as it runs, show what's happening with each simulation of the game. It should also show the results at the end. With each game simulated, the program should print the following information:

  1. The number of the door that contains the prize.

  2. The number of the door initially guessed by the simulated contestant.

  3. The number of the door shown by Monty Hall that has a dud prize.

  4. Whether staying or switching would be the correct move for the player under this circumstance.

After all of the trials have been performed, the program should print the number of times the contestant would have won by switching, and the number of times she would have won by staying. Specifically, the output should have exactly this format:

Number of trials? 2
Prize: 2  Guess: 2  Shown: 1  STAY   to win
Prize: 0  Guess: 2  Shown: 1  SWITCH to win
Switch would win: 1
Stay would win:   1
    

Submitting your work

When your work is complete, use the cs11-submit program again. For this lab, you will submit your work with the following command at the shell prompt:

cs11-submit project-1 MakeADeal.java

This project is due on Wednesday, March 5th at 11:59 pm

Scott F. H. Kaplan
Last modified: Fri Mar 28 11:19:08 EDT 2008