A Walker located at the origin in a Cartesian grid of streets randomly picks one of four directions and moves to the next intersection, then again randomly picks one of four directions, moves in that direction to the next intersection, and so on.
Write a Walker
class that keeps track of its current x
, y
location. Include three methods: getX()
, getY()
, and move()
, which causes the walker to move in a random direction (up, down, left, or right).
Then write a WalkerRunner
program with a main()
that creates a Walker
and tracks its motion over time. The program should display the walker’s coordinates and number of moves made until: