Question: 1- Define the Circle2D class that contains: Two double data fields named x and y that specify the center of the circle with get methods.

1- Define the Circle2D class that contains:

  • Two double data fields named x and y that specify the center of the circle with get methods. (5 points)
  • A data field radius with a get method. (5 points)
  • A no-arg constructor that creates a default circle with (0, 0) for (x, y) and 1 for radius. (5 points)
  • A constructor that creates a circle with the specified x, y, and radius. (5 points)
  • A method getArea() that returns the area of the circle.(5 points)
  • A method getPerimeter() that returns the perimeter of the circle.(5 points)
  • A method contains(double x, double y) that returns true if the specified point (x, y) is inside this circle. See Figure (a). (15 points)
  • A method contains(Circle2D circle) that returns true if the specified circle is inside this circle. See Figure (b).(12.5 points)
  • A method overlaps(Circle2D circle) that returns true if the specified circle overlaps with this circle. See Figure (c) below.(12.5 points)

Implement the class.

2- Write a test program TestCircle2D.java that creates a Circle2D object:

  • new Circle2D(2, 2, 5.5)(6 points)
  • displays its area and perimeter(6 points)
  • displays the result of c1.contains(3, 3)(6 points)
  • displays the result of c1.contains(new Circle2D(4, 5, 10.5))(6 points)
  • displays the result of c1.overlaps(new Circle2D(3, 5, 2.3))(6 points)

a) A point is inside the circle. (b) A circle is inside another circle. (c) A circle overlaps another circle.

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!