Question: java coding 2.1. Bean Machine The bean machine is a device for statistical experiments. It consists of an upright board with evenly spaced nails (or

 java coding 2.1. Bean Machine The bean machine is a device

for statistical experiments. It consists of an upright board with evenly spaced

java coding

2.1. Bean Machine The bean machine is a device for statistical experiments. It consists of an upright board with evenly spaced nails (or pegs) In a triangular form, as shown in Figure 7.13 from our assigned textbook. (b) (0) FIGURE 7.13 Each ball takes a random path and falls into a slot Balls are dropped from the opening at the top 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 to simulate the bean machine that has 8 slots as shown in the figure. Your program should prompt the user to enter the number of balls to drop. Simulate the falling of each ball by printing its path. For example, the path for the ball in Figure 7.13(b) is LLRRLLR and the path for the ball in Figure 7.13(c) is RLRRLRR. Note that there are 7 levels of nails, so your path should be 7 letters (not 8). Create an array called slots. Each element in slots store the number of balls in a slot. Each ball falls into a slot via a path. The number of "R"s 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 RRLLLLL, the ball falls into slots[2). You should create a method to randomly drop a ball and return the position in array that the ball dropped into. You will pass in the number of slots as that will determine how many levels of nails the ball must pass through (numberofslots-1). This method should also print out the path that the ball took (e.g. LRLLRLL). Here is the suggested method header: public static int dropBall (int numberoeslots) Generate the path the ball took using the random method from the Math class Print the path on the screen Return the slot number the ball fell into Display the final buildup of the balls in the slots using a histogram. Create a method with the following header: INFO 2312 Assignment #2 Spring 2021 public static void printGameResults (int slots) Below is a sample run of my program using 10 balls and the desired output. Note that the slot number displayed is +1 more than the array index which is zero-based in this example, 6 balls fell into slot 3 (index 2 in the array, the path would have two "R"s and five "L"s). Welcome to the Bean Game! You will drop balls in the Beam Game and they will hit a series of nails and fall into one of 8 slots. After all the balls are dropped, the resulting accumulation of balls in each slot will be displayed for you to see! Enter the number of balls to drop: 10 Ball 1: RLLRRRR Ball 2: LLLLLRR Ball 3: LLLLL RR Ball 4: LLL RLRL Ball 5: LLR LRRL Ball 6: LLL RLRL Ball 7: L RULLRL Ball B: RL LLLLL Ball 9: LLRLLRL Ball 10: RRRRLLR Game results TOR 1 2

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!