Class AlleyWalker

java.lang.Object
  extended by AlleyWalker

public class AlleyWalker
extends java.lang.Object

A class that simulates a random alley walk.

Version:
11/7/06
Author:
Dave Reed

Constructor Summary
AlleyWalker()
          Constructs a random alley walker.
 
Method Summary
 int getNumSteps()
          Gets the number of steps taken by the walker so far.
 int getPosition()
          Gets the current position of the walker (relative to its starting place).
 void reset()
          Resets the position and number of steps for the walker.
 void step()
          Simulates a single step of the walker, randomly moving one position to the right (the positive direction) or to the left (the negative direction).
 void stepToDistance(int distance)
          Simulates repeated steps of the walker, until it reaches a specific distance from its starting place (in either direction).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AlleyWalker

public AlleyWalker()
Constructs a random alley walker.

Method Detail

getNumSteps

public int getNumSteps()
Gets the number of steps taken by the walker so far.

Returns:
the number of steps

getPosition

public int getPosition()
Gets the current position of the walker (relative to its starting place).

Returns:
the current position (positive = right, negative = left)

reset

public void reset()
Resets the position and number of steps for the walker.


step

public void step()
Simulates a single step of the walker, randomly moving one position to the right (the positive direction) or to the left (the negative direction).


stepToDistance

public void stepToDistance(int distance)
Simulates repeated steps of the walker, until it reaches a specific distance from its starting place (in either direction).

Parameters:
distance - the distance the walker must reach before stopping