### CSC 221: Computer Programming I Spring 2008 HW7: Marble Jar Simulations

In this assignment, you will make use of previously defined Java classes to help solve two brain-teaser puzzles. These puzzles, which are common among statisticians and discrete mathematicians, involve drawing black and white marbles from a jar.

1. Suppose a jar contains the same number of black and white marbles. If you reach in and pull out two random marbles, are they more likely to be the same color or different colors?

2. Suppose a jar has an arbitrary mixture of black and white marbles. As long as there are at least two marbles in the jar, draw two random marbles and:
• If they are the same color, throw them both away and add a brand new black marble to the jar.
• If they are different colors, throw away the black one and return the white marble to the jar.
Can the marble drawing process go on forever? Furthermore, if you are told the initial contents of the jar, can you predict the final outcome?

### PART 1: PuzzleOne

The MarbleJar and PuzzleOne classes have been provided for you.

• Based on simulation results using these classes, what is the answer to this puzzle? Are the two marbles more likely to be same color or different colors? Can you explain why?
• Does increasing the total number of marbles in the jar affect the answer in any way?

### PART 2: PuzzleTwo

Design and implement a class named `PuzzleTwo` that can be used to simulate the steps in the second puzzle. The user should be able to somehow specify the number of black and white marbles in the jar, then view the steps in the simulation. As each pair of marbles is drawn, a message describing the action taking place (including its number in the process), should be printed. The simulation should stop if fewer than two marbles remain in the jar.

For example, the output produced by the method should look like the following:

1: I drew black and white -- replacing a white marble. 2: I drew white and white -- replacing a black marble. 3: I drew white and black -- replacing a white marble. 4: I drew white and black -- replacing a white marble. . . . 18: I drew black and white -- replacing a white marble. 19: Only one marble left... it is white.
• Based on repeated simulation results, what is the answer to this puzzle? Can the process of drawing and replacing marbles go on forever? Why or why not?
• If you know the initial contents of the jar, can you predict the final outcome? Explain.