Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Change the constructor of the class Circle so that it allows you to specify the color during construction. Add an accessor method to Circle that

  1. Change the constructor of the class Circle so that it allows you to specify the color during construction.
  2. Add an accessor method to Circle that returns the diameter of a circle.
  3. Add an accessor method to Circle that returns the color of a circle.
  4. Add a mutator method to Circle that will change a circle's x position to a new x.
  5. Add a mutator method to Circle that will change a circle's y position to a new y.
  6. Add a mutator method to Circle that moves a circle to a new location: (x, y).
  7. Add an accessor method to Circle that returns the distance of the circle from (0, 0): the origin. Use: (int)(Math.sqrt(someNumber)) to get the square root of someNumber. For example, the following code stores the value 10 in the variable x: int num = 100; int numSquareRoot = (int)(Math.sqrt(num));
  8. Complete the displayDetails method. It should display a circle's diameter, color, and coordinates exactly as in the following example: The red circle at (55, 120) has a diameter of 5.image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
public class Circle { private int diameter; private int xPosition; private int yPosition; private String color: private boolean isVisible; ** * Create a new circle at default position with default color. */ public Circle(int newdiameter) diameter = newdiameter: xPosition = 20; yPosition = 60; color = "blue": isVisible = false; //** ************************************ // Your code goes here. You may also want to change the comment // immediately above the constructor to reflect your code changes. public void display Details { System.out.println("The " + xPosition + " xPosition"); } /** + Make this circle visible. If it was already visible, do nothing. public void makeVisible() { if (!isVisible) { isVisible = true; draw(); } /** * Make this circle invisible. If it was already invisible, do nothing. public void make Invisible() { if (isVisible) { erase(); isVisible = false; /** * Move the circle a few pixels to the right. */ public void moveRight() moveHorizontal(20): /** * Move the circle a few pixels to the left. */ public void moveLeft() { moveHorizontal(-20); } /** * Move the circle a few pixels up. */ public void moveUp moveVertical(-20); * Move the circle a few pixels down. public void moveDown() { moveVertical (20): * Move the circle horizontally by 'distance' pixels. */ public void move Horizontal(int distance) erase(): xPosition += distance; draw(); /** * Move the circle vertically by 'distance' pixels. */ public void moveVertical(int distance) { erase(): yPosition += distance; draw(); } * Slowly move the circle horizontally by 'distance' pixels. */ public void slowMoveHorizontal(int distance) { int delta; if(distance = 0. */ public void changeSize(int newDiameter) { if (newDiameter >= 0) { erase(); diameter = new Diameter; draw(); } } /** * Change the color. Valid colors are "red", "yellow", "blue", "green", * "magenta" and "black". */ public void changeColor(String newColor) { if (newColor.equals("red") || newColor.equals("yellow") || newColor.equals("blue") 11 newColor .equals("green") || newcolor.equals("magenta") || newColor .equals("black")) { color = newColor: draw(); * Draw the circle with current specifications on screen. */ private void draw() { if(isVisible) { Canvas canvas = Canvas.getCanvas(); canvas.draw(this, color, new Ellipse2D.Double(xPosition, yPosition, diameter, diameter)); canvas.wait(10); } * * Erase the circle on screen. */ private void erase() { if(isVisible) { Canvas canvas = Canvas.getCanvas(); canvas.erase(this)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions

Question

3. Develop a case study.

Answered: 1 week ago