Java

Random Walk 2

6 points

This is a 2D random walk program; the difference from the previous random walk program is that we allow the robot to randomly choose one of four directions in which to move.

You'll have some changes to make to the "extra credit" version of random walk #1. I added a '2' to the end of the class names: RandomWalker became RandomWalker2 and ManageWalk became ManageWalk2. In RandomWalker2, add methods 'stepNorth' and 'stepSouth'. Add a 'getRow' method to accompany 'getCol'.

In ManageWalk2, modify the 'walk' method to allow randomness in the robot's east vs. west decision and its north vs. south decision. Later in 'walk', calculate the robot's horizontal displacement and its vertical displacement. Then use the Pythagorean Theorem (or the distance formula) to calculate the robot's overall displacement, which is what we're interested in.

Once you've got the 2D version working, take the same steps that you took with random walk #1. Simulate each scenario 1000 times. Allow the robot to take 10, 30, 100, 300, 600 and 1000 steps. For each of the 6 scenarios, use Excel to find the robot's average displacement. Record the displacements in a table and make a graph of the results.

 

Starting Point

You can use your extra-credit version of the first random walk program as a starting point for this program.