Producer-Consumer (6.6)

In a computer game, coconuts fall from a tree. Three monkeys on the ground must catch the coconuts before they hit the ground and eat them. Suppose that a new coconut falls between 0 and 250 milliseconds with uniform distribution. The monkey that catches the coconut is busy for 500 milliseconds to eat it before it can catch another one. The game ends when a coconut hits the ground.

Model the game using a Producer-Consumer pattern. Your program should produce a trace showing the events of a game. Run your program a few times to count how many coconuts fall from the tree before the game ends (usually between 10 and 19 on the instructor's system).