bladez89
12-03-2009, 02:43 AM
Hey guys :) My professor is letting me do this extra credit assignment. I have already made a source code for a Monty Hall Problem without GUI, but this one calls for a code with GUI, and I have no idea how to do it. Please help me!!! It isn't due until 12/14/09 so I have some time, but I wanted to get it done so any help I can get I would greatly appreciate!!! :) Here is the question:
The “Monty Hall Problem” takes its name from the classic television game show “Letʼs
Make a Deal,” which was hosted by Monty Hall. During the show, a contestant is shown
three doors, labeled 1, 2, and 3. One of the doors hides a prize (like a brand new sports
car); the remaining doors each conceal a (live) goat. The host (Monty Hall) is the only
one who initially knows what is behind which door.
After the contestant selects one of the three doors, Monty opens one of the other doors
to reveal a goat. The prize is still located behind one of the unselected doors, and the
other door still conceals a goat. The contestant now has the option of sticking with his
original choice or switching to the other door. Monty then opens the selected door to
reveal what the contestant has ultimately won.
This problem is a favorite in probability and statistics classes. Should the contestant
switch doors when he has the chance? Should he stay with his original choice? Does it
make a difference? How often does the contestant leave with the sports car, and how
often with a goat?
Write a simple GUI program that simulates this game. Use a random number (1, 2, or 3)
to select the winning door (see the end of this document for a brief description of Javaʼs
Random class). The GUI should display three buttons, one for each door. The user can
click on a button to select that door. After the user chooses a door, the program should
disable one of the other door buttons and change its label to reflect that it hid a goat
(Hint: use JButtonʼs setEnabled() and setText() methods for this part). The user
can then click on one of the two remaining buttons to open that door, at which point
those door buttons are relabeled with their contents.
Your GUI should also include a “reset” button that will allow the player to try again.
Include JLabels that show how many times the game has been played, how many
times the contestant switched doors, how many times the player won the car, and how
many times the player won a goat. Note that JLabel also has a setText() method.
The “Monty Hall Problem” takes its name from the classic television game show “Letʼs
Make a Deal,” which was hosted by Monty Hall. During the show, a contestant is shown
three doors, labeled 1, 2, and 3. One of the doors hides a prize (like a brand new sports
car); the remaining doors each conceal a (live) goat. The host (Monty Hall) is the only
one who initially knows what is behind which door.
After the contestant selects one of the three doors, Monty opens one of the other doors
to reveal a goat. The prize is still located behind one of the unselected doors, and the
other door still conceals a goat. The contestant now has the option of sticking with his
original choice or switching to the other door. Monty then opens the selected door to
reveal what the contestant has ultimately won.
This problem is a favorite in probability and statistics classes. Should the contestant
switch doors when he has the chance? Should he stay with his original choice? Does it
make a difference? How often does the contestant leave with the sports car, and how
often with a goat?
Write a simple GUI program that simulates this game. Use a random number (1, 2, or 3)
to select the winning door (see the end of this document for a brief description of Javaʼs
Random class). The GUI should display three buttons, one for each door. The user can
click on a button to select that door. After the user chooses a door, the program should
disable one of the other door buttons and change its label to reflect that it hid a goat
(Hint: use JButtonʼs setEnabled() and setText() methods for this part). The user
can then click on one of the two remaining buttons to open that door, at which point
those door buttons are relabeled with their contents.
Your GUI should also include a “reset” button that will allow the player to try again.
Include JLabels that show how many times the game has been played, how many
times the contestant switched doors, how many times the player won the car, and how
many times the player won a goat. Note that JLabel also has a setText() method.