Lab 10: Post-Lab Assignment

Due Friday, November 14, 2008 by 4:00 pm

In this post lab you will extend the RandomWalk class you created in lab. In using random walks to simulate behavior it is often of interest to know how far away from the initial position the object gets as it moves. There are several different possibilities for measuring the distance. In this case it makes sense to use Manhattan distance - the sum of the vertical and horizontal distances from the starting point. For example, the Manhattan distance from the point (20, 350) to (200, 100) is 430 (horizontal distance of 180 + vertical distance of 250).

Add to your RandomWalk class a method that returns the maximum Manhattan distance from the initial point that the walk has moved. In order to do this you will need a new instance variable to keep track of the maximum distance that is updated every time a step is taken. Be sure to test the method before proceeding. Next, create a program that uses your RandomWalk class to compute maximum Manhattan distances of multiple random walks and prints out their average. Each walk should only terminate when the maximum number of steps has been reached (not when it is out of bounds). This program should prompt the user to enter the size of each step, the maximum number of steps, and the number of maximum distances to average.

Requirements: As usual you must use good programming style and document your program (including header documentation that describes what the program does and includes your name, documentation on the main method, and in-line documentation to mark the main sections of code). Your program should be in the lab10 package created in lab.

Hand In