A random walk begins at a point and repeatedly takes a step


Details

A random walk begins at a point and repeatedly takes a step in a randomly chosen direction. In our version, the random walk will start at the center of a circle and continue until it goes outside the circle. Each step will be randomly chosen from one pixel up, one pixel down, one pixel left, and one pixel right (this kind of random walk is called the "drunkard's walk"). Call the nextInt method on a Random object to generate an integer between 0 and 3 and map each value to one of the steps. The random walk will be drawn on a Graphics object. Here is an example for a circle with a radius of 100.

The user should be asked for the radius of the circle and the color of the circle (from at least two choices for colors). The program should print the values that the user enters. The program should draw the circle on a DrawingPanel that is big enough to hold the circle, leaving some space (but not a lot of space) around the circle. Call the drawCircle on your Graphics object to draw the circle. Each step of the random walk should drawn by calling the drawLine method on your Graphics object. To animate the walk, call the sleep method on your DrawingPanel to pause a millisecond between each step. After the random walk is finished, the number of steps of the random walk should be printed.

Loops

This lab must have a while loop to ensure that the radius of the circle is between 50 and 400.

This lab must have a while loop to ensure that the user selects one of the color choices.

This lab must have a while loop to continue drawing the random walk until the walk leaves the circle.

Methods

Write and use the following methods to support your random walk.

Write a boolean method to determine whether the current position of the random walk is outside the circle. What values do you need to make this decision? These values need to be parameters of the method. How will you calculate the distance from the center of the circle? You did something similar in Lab 5.

Write a boolean method to determine whether a String answer entered by the user matches a String choice for the question.

public static boolean matchesChoice(String answer, String choice)

For example, if "blue" is one of the choices for a color, then the user should be able to enter "blue", "Blue", "BLUE", "b", or "B" to answer with this color. However, "bluish", "navyBlue", or "blueGreen" should not match. That is,

matchesChoice("blue", "blue") should return true.
matchesChoice("Blue", "blue") should return true.
matchesChoice("B", "blue") should return true.
matchesChoice("bluish", "blue") should return false.
matchesChoice("navyBlue", "blue") should return false.
matchesChoice("blueGreen", "blue") should return false.

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: A random walk begins at a point and repeatedly takes a step
Reference No:- TGS0646200

Expected delivery within 24 Hours