C2.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. FIGURE 7.1) Each ball takes a random puth and falls into a skot 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(e) 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 RRLLULL, 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 (numberorslots-1). This method should also print out the path that the ball took (e.g. LALLALL). Here is the suggested method header: public static int dropBall (int numberofslots) 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: 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: 18 Ball 1: RLLRRRR Ball 2: LLLLLRR Ball 3: LLLLLRR Ball 4: LLL RLRL Ball 5: LLRL Ball 6: LLLR Ball 7: LRLLL Ball 8: RLLLLL Ball 9: LLRLL Ball 10: RRRR Game results: II 101 11 10 IL i ijoj in 1 1 10 11 i i joj i joj i jojojoj joj 12345678 C2.2: Stopwatch Design a public class named Stopwatch. The class contains: . . . long data fields startTime and endTime. A no-argument constructor that initializes startTime and endtime with the current time. A method named start() that resets the start Time to the current time. A method named stop () that sets the endTime to the current time. A method named getElapsedTime() that returns the elapsed time for the stopwatch in milliseconds (endTime startTime). Use the System Class method currentTimeMillis() to obtain the current time. NOTE: Please define the public Stopwatch class in it's own Java file separats from the test program as shown in Lesson #6. Write a test program to test the Stopwatch class. To test its operation, a large array of 100,000 double numbers in the range of 0 to 100,000 is generated using the random method from the Math class. Then, using a Stopwatch object, the time is measured to sort this array, To make it more interesting the performance of three sorting algorithms will be compared: 1. The bubble sort algorithm 2. The selection sort algorithm 3. The dual-pivot quicksort algorithm (this is the sort algorithm used in the sort method of the Arrays class as demonstrated in class). You will have to implement the bubble sort and selection sort algorithm yourself (search on-line for the algorithms - this will test your resourcefulness). Here are the suggested method headers for both of these algorithms: public static void bubbleSort (doublet list) Sort the list array in ascending order public static void selectionSort (double[1 list) Sort the list array in ascending order The dual-pivot quicksort algorithm is already implemented for you through the sort method in the Arrays class as was demonstrated in class. NOTE: when you create the unsorted array of 100,000 double numbers, you will have to make two more copies of that array before you test any sorting. These copies are required because the sorting algorithms will sort the list array and so you cannot use it again as it is now sorted. Also, you want to test all three algorithms with the same unsorted data you generated to have a fair comparison. You can use the copyof method from the Arrays class to perform this copy. . Remember: For each problem, include several test runs of the program to show successful runs of your program, with both valid and invalid data (to show that you are checking for invalid data, if applicable) Please ensure the program is well designed and follows accepted style guidelines (e.g. variable naming, indentation, spacing). Please ensure the program is well documented, including the overall purpose of the program and documenting all the major sections of the code. NEW: Please ensure your output includes a line that identifies you. For example: System.out.println("Written by Warren Edwards, INFO 2312 812")