Question: In this discussion you will create a new object called RandomWalker. Start by creating a new class and copy RandomWalker.java template to it . You

In this discussion you will create a new object called RandomWalker. Start by creating a new class
and copy RandomWalker.java template to it. You will also create your own class TestRandomWalker
to test your object. Remember, names of methods and class must match the names in the problem
description. Please make sure to include meaningful comments when you solve problems.
RandomWalker:
RandomWalker is an object should keep track of its (x,y) location. All walkers start at the
coordinates (0,0). When a walker is asked to move, it randomly moves either left, right, up or
down. Each of these four moves should occur with equal probability. The resulting behavior is
known as a "random walk."
Each RandomWalker object should have the following public methods. You may add whatever
fields or methods you feel are necessary to implement these methods:
Fields
Your fields have to be of type int only. You can't use object Point. The fields also have to be private.
Tip 1: You need to remember x and y coordinates as well as number of steps.
Constructor
You must have a constructor that doesn't accept any parameters but initializes all field. Recall your
objected should start at (0,0) location. The object also didn't do any steps before it was created.
Note: You want to use this key word every time you need to interact with fields.
Behaviors
get X()
Returns this random walker's current x-coordinate.
getY ()
Returns this random walker's current y-coordinate.
getsteps ()
Returns the number of steps this random walker has taken.
Tip for gets: This is similar to Point class get we did in class.
move ()
This behaviour doesn't accept any parameters! You will use class Random to generate a random
integer number between 0 and 3 inclusive. When method move() depending on the number
"rolled" random walker to make one of the 4 possible moves (up (0), down (1), left (2), or right(3)) make sure to modify all fields accordingly. this method
 In this discussion you will create a new object called RandomWalker.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!