Write a boolean method

Assignment Help Basic Computer Science
Reference no: EM13307513

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.

Reference no: EM13307513

Questions Cloud

What is the speed of light in diamond : Light is refracted through diamond from air. If the angle of incidence is 30 °, what is the speed of light in diamond
What is the equivalent concentration at temperature : The concentration of CO2 is 400ppm what is the equivalent concentration in ug/m^3 at temperature of 22C & pressure of 103.198 kPa.
What is the mass of the clas : a 5kg Potter's wheel (model as a disk) with radius 0.3m is spinning at 5 rad/s. what is the mass of the clas
Is the state water-quality standard being met downstream : If the state standard downstream is not met, the state has informed town 1 that it must treat its sewage further so the downstream standard is met. Use a mass balance approach to show that the state's request is unfeasible.
Write a boolean method : 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.
Explain what aspects of the system should be evaluated : What aspects of the system do you think should be evaluated. Are those aspects considered in the evaluation. What is the experimental testbed used. What experiments were performed. Details of experimental results. What aspects of the system were n..
How thick is the wall of my sphere : If i have a hollow copper sphere that has an outer diameter of 20.00 cm that is floating so that everything is just submerged in a bucket of water
What is the value of the test statistic and the chi-square : What is the value of the test statistic and the chi-square table, the most accurate statement that can be made about the p-value
What is its position as a function of time : A body of mass 5.0 kg is suspended by a spring, which stretches 10 cm when the mass is attached. What is its position as a function of time

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Determine maximum number of telephones end office support

With mean call duration of six minutes. Ten percent of calls are long distance. Determine the maximum number of telephones an end office can support?

  Methods-majority of target audience can play applications

What are some methods that we can guarantee that majority of target audience can play applications?

  Draw the circuit for a 2-input xnor gate

Draw the circuit for a 2-input XNOR gate using at most two tri-state elements (tri-state buffer or tri-state inverter) and one inverter.

  Write a sql query to display customer id

Use joining technique (WHERE commands is preferred[1]) to write a SQL query to display customer ID, customer name, and customer address for all the customers who are doing business with PVFC in the territory of Southwest.

  What information does the data mining generate

What information does the data mining generate?

  Write a program that uses a recursive method

A palindome is a string that reads the same both forward and backward. For example,the string "madam" is a palindrome. write a program that uses a recursive method to check whether a string is a palindome.

  Explain business scenario and specify types of constraints

Explain a business scenario and specify the types of constraints that would be appropriate to make sure the integrity of the database. For example, an airline reservation system should not make a reservation.

  Macro running in response to form button

All of the following are events except: a macro running in response to a form button being clicked, changing the data in a cell, clicking on a control button or opening or closing an Excel workbook.

  What value is read into the variables by the following code

What value is read into the variables by the following code?

  You are to design and develop three html5 pages

You are to design and develop three HTML5 pages themed on Manchester. The pages should be optimised for delivery on a tablet, and should contain the following:

  Review and discuss methods for it managers to maintain

Review and discuss methods for IT managers to maintain their skills while gaining new managerial skills

  Limitations of the use of ai technologies

Determine some of the limitations or dangers you see in the use of AI technologies such as expert systems, virtual reality, and intelligent agents?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd