Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Geometry: The Circle2D class) Define the Circle2D class that contains: Two doub

ID: 3657048 • Letter: #

Question

(Geometry: The Circle2D class) Define the Circle2D class that contains: Two double data fields named x and y that specify the center of the circle with get methods. A data field radius with a get 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.15a). A method contains(Circle2D circle) that returns true if the specfied circle is inside this circle (see Figure 10.15b). A method overlaps(Circle2D circle) that returns true if the specified circle overlaps with this circle (see Figure 10.15c).

Explanation / Answer

package circle2D; public class Circle2D { //center point of the circle private double X,Y; //radius private double rad; double dist=0.0; public Circle2D() { X=0; Y=0; rad=1.0; } public Circle2D(double CenterX,double CenterY,double radius) { X = CenterX; Y = CenterY; rad = radius; } public double getRadius() { return rad; } public double getArea() { return Math.PI*rad*rad; } public double getPerimiter() { return 2*Math.PI*rad; } public boolean isContain(double x,double y) { dist = Math.sqrt((x-X)*(x-X)-(y-Y)*(y-Y)); if(dist>rad) return false; else return true; } public boolean isCircleContains(Circle2D circle) { dist = Math.sqrt((X-circle.X)*(X-circle.X)-(Y-c… if(dist+circle.rad