Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 in Figure 7.13.

http://4.bp.blogspot.com/--M-PF-DNJw0/VlLHhSDeTUI/AAAAAAAABJ0/IeYyNstb3Ow/s1600/pic%2B713.jpg

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.

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 (maximum 50) in the machine. Simulate the falling of each ball by printing its path. For example, the path for the ball in Figure 7.13b is LLRRLLR and the path for the ball in Figure 7.13c is RLRRLRR. Display the final buildup of the balls in the slots in a histogram. Here is a sample run of the program:

(Hint: Create an array named slots. Each element in slots stores the number of balls in a slot. Each ball falls into a slot via a path. The number of Rs in a path is the position of the slot where the ball falls. For example, for the path LRLRLRR, the ball falls into slots[4], and for the path is RRLLLLL, the ball falls into slots[2].)

0 jo o Bo 9 O 0 FIGURE 7.13 Each ball takes a random path and falls into a slot. 001 O o Enter the number of balls to drop: 5 Enter the number of slots in the bean machine: 8 Enter LRLRLRR RRLLLRR LLRLLRR RRLLLLL LRLRRLR 0 0 000

Step by Step Solution

There are 3 Steps involved in it

Step: 1

BeanMachinejava import javautilScanner public class BeanMachine public stati... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Document Format ( 2 attachments)

PDF file Icon
60951fd48e7cd_25569.pdf

180 KBs PDF File

Word file Icon
60951fd48e7cd_25569.docx

120 KBs Word File

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

College Algebra Graphs and Models

Authors: Marvin L. Bittinger, Judith A. Beecher, David J. Ellenbogen, Judith A. Penna

5th edition

321845404, 978-0321791009, 321791002, 978-0321783950, 321783956, 978-0321845405

More Books

Students also viewed these Programming questions