Question: The bean machine, also known as a quincunx or the Galton box, is a device for statistics experiments named after English scientist Sir Francis Galton.

The bean machine, also known as a quincunx or the Galton box, is a device for statistics experiments named after English scientist Sir Francis Galton. It consists of an upright board with evenly spaced nails (or pegs) in a triangular form, as shown below.

Balls are dropped from the opening of the board. Every time a ball hits a nail, it has a 50% chance of falling to the left or to the right. The piles of balls are accumulated in the slots at the bottom of the board.

Specifications

Write a program that simulates the bean machine. Your program should prompt the user to enter the number of the balls and the number of the slots in the machine. Your program must use both a Runner class and a Machine class.

I would recommend a constructor that takes the number of slots and balls as parameters, a method that simulates the balls dropping through the machine, a method that prints the paths of the balls, and a method that prints the diagram.

Simulate the falling of each ball by printing its path. For example, the path for the ball in (b) is LLRRLLR and the path for the ball in (c) is RLRRLRR. Display the final buildup of the balls in the slots in a histogram (similar to what it looks like in the diagram above).

Sample Outputs

Enter the number of balls to drop: 5 Enter the number of slots in the bean machine: 8 LRLRLRR RRLLLRR LLRLLRR RRLLLLL LRLRRLR O O __OOO___ 
Enter the number of slots for the machine: 4 Enter the number of balls: 25 LRR LLR RRR RRR LRR LLR RRR RLR LLR RLL LLR RRL LRR RRL RLL RLR LLL RRR LLR LLR RRR LRR LLL RRR LRR O OO OO OOO OOO OOO OOO OOOO OOOO

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!