Answer the prompt with given main method: Code: import java.awt.*; public class TestRandomWalker { public static final int STEPS = 500; public static void main(String[] args) { RandomWalker walker = new RandomWalker(); // instantiate Walker object DrawingPanel panel = new DrawingPanel(500, 500); Graphics g = panel.getGraphics(); // advanced features -- center and zoom in the image panel.getGraphics().translate(250, 250); panel.getGraphics().scale(4, 4); // make the walker walk, and draw its movement int prevX = walker.getX(); // initialize Walker display int prevY = walker.getY(); for (int i = 1; i <= STEPS; i++) { g.setColor(Color.BLACK); g.drawLine(prevX, prevY, walker.getX(), walker.getY()); // update Walker display walker.move(); // move Walker 1 step prevX = walker.getX(); // update x value prevY = walker.getY(); // update y value g.setColor(Color.RED); g.drawLine(prevX, prevY, walker.getX(), walker.getY()); // update Walker display int steps = walker.getSteps(); // record Walker steps if (steps % 10 == 0) { System.out.println(steps + " steps"); }
Answer the prompt with given main method:
Code:
import java.awt.*;
public class TestRandomWalker {
public static final int STEPS = 500;
public static void main(String[] args) {
RandomWalker walker = new RandomWalker(); // instantiate Walker object
DrawingPanel panel = new DrawingPanel(500, 500);
Graphics g = panel.getGraphics();
// advanced features -- center and zoom in the image
panel.getGraphics().translate(250, 250);
panel.getGraphics().scale(4, 4);
// make the walker walk, and draw its movement
int prevX = walker.getX(); // initialize Walker display
int prevY = walker.getY();
for (int i = 1; i <= STEPS; i++) {
g.setColor(Color.BLACK);
g.drawLine(prevX, prevY, walker.getX(), walker.getY()); // update Walker display
walker.move(); // move Walker 1 step
prevX = walker.getX(); // update x value
prevY = walker.getY(); // update y value
g.setColor(Color.RED);
g.drawLine(prevX, prevY, walker.getX(), walker.getY()); // update Walker display
int steps = walker.getSteps(); // record Walker steps
if (steps % 10 == 0) {
System.out.println(steps + " steps");
}
panel.sleep(100);
}
}
}
![1. Define a class named Randomwalker. A Randomwalker 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." (A 2-dimensional random walk example is pictured at right.)
Each Randomwal ker object should have the following public methods. You may add whatever fields or
methods you feel are necessary to implement these methods:
move ()
Instructs this random walker to randomly make one of the 4 possible moves (up, down, left, or right).
getX ()
Returns this random walker's current x-coordinate.
getY ()
Returns this random walker's current y-coordinate.
getsters ()
Returns the number of steps this random walker has taken.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F6175b5e0-5a2d-4711-92a7-8016af7d3c79%2F887f6533-7318-45d2-a9fe-800c0a0a79cc%2F6g1qs95_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)