Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.
Define the Circle2D class that contains: Two double data fields named x and y that specify the center of the circle with getter methods. A data field...
Define the Circle2D class that contains:
■ Two double data fields named x and y that specify the center of the circle with getter methods.
■ A data field radius with a getter method.
■ A no-arg constructor that creates a default circle with (0, 0) for (x, y) and 1
for radius.
■ A constructor that creates a circle with the specified x, y, and radius.
■ A method getArea() that returns the area of the circle.
■ A method getPerimeter() that returns the perimeter of the circle.
■ A method contains(double x, double y) that returns true if the
specified point (x, y) is inside this circle (see Figure 10.21a).
■ A method contains(Circle2D circle) that returns true if the specified circle is inside this circle (see Figure 10.21b).
■ A method overlaps(Circle2D circle) that returns true if the specified circle overlaps with this circle (see Figure 10.21c).
Use the following code for the methods contains and overlaps:
public boolean contains(double x, double y) {
// MyPoint is defined in Exercise09_04
double d = distance(x, y, this.x, this.y) ;
return d <= radius;
}
public boolean contains(Circle2D circle) {
double d = distance(this.x, this.y, circle.x, circle.y);
return d + circle.radius <= this.radius;
}
public boolean overlaps(Circle2D circle) {
// Two circles overlap if the distance between the two centers
// are less than or equal to this.radius + circle.radius
// MyPoint is defined in Exercise09_04
return distance(this.x, this.y, circle.x, circle.y)
<= radius + circle.radius;
}
private static double distance(double x1, double y1,
double x2, double y2) {
return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
Here is a sample run for a point 2, 2 with a radius of 5.5:
I am attaching all files.
- Attachment 1
- Attachment 2