Question: JAVA In Random Numbers 1 you wrote a method that would run a single round of a random walk and return the number of steps

In Random Numbers 1 you wrote a method that would run a single round of a random walk and return the number of steps that it took for the walk to end. For example a walk to 10 might take anywhere from 10 to 200 or more steps. Your question on this assignment is to take that method, and to determine the AVERAGE number of steps it takes. To do this you are going to run your method from the first program 10000 times, and find the total number of steps needed and then divide it to find the average. So for example if I ask the computer what is the average number of steps for a size 20 walk, it might return back that the average number of steps is 397.33 So you need to ask the user what size walk they want to know about, then run the method with that number 10,000 (ten thousand) times, and find the average number of steps. Then print out that number. A sample of what your output should look like: ---- GRASP exec: java ProgramNumber12 What size walk do you want to test? 100 For a walk of size 100, after 10.000 tries, on average it took 10029.12 steps to get there. GRASP: operation complete. In Random Numbers 1 you wrote a method that would run a single round of a random walk and return the number of steps that it took for the walk to end. For example a walk to 10 might take anywhere from 10 to 200 or more steps. Your question on this assignment is to take that method, and to determine the AVERAGE number of steps it takes. To do this you are going to run your method from the first program 10000 times, and find the total number of steps needed and then divide it to find the average. So for example if I ask the computer what is the average number of steps for a size 20 walk, it might return back that the average number of steps is 397.33 So you need to ask the user what size walk they want to know about, then run the method with that number 10,000 (ten thousand) times, and find the average number of steps. Then print out that number. A sample of what your output should look like: ---- GRASP exec: java ProgramNumber12 What size walk do you want to test? 100 For a walk of size 100, after 10.000 tries, on average it took 10029.12 steps to get there. GRASP: operation complete. 10 ( 6 7 import java.util. Random; 8 9 public class Assignment 11 11 public static int randomwalk(int x) // create int method 12 { 13 int position - , maximum - @, steps - @; // start at 14 15 16 while ((* (-1)) position) // while loop, repeat randon 17 { 18 Random key - new Random(); 19 System.out.println("position + position); // display each position 20 int step - key.nextInt(2) -2 + 1; // Increase or decrese position by 1 or -1 21 position - position + step: 22 maximum - Math.max(maximum, position); get the greatest number 23 steps ++; 24 } 25 26 System.out.println("position + position); 27 28 return steps; / return 29 30 ) 31 32 public static void main(String[] args) la program 33 { 34 ant r = randomwalk(30); 35 System.out.println("Steps: + r); Welling the function 36 3 37)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
