Define the Circle2D class that contains Two double data fiel
Solution
// Circle2D.java
public class Circle2D
{
private double x, y;
private double radius;
double getRadius()
{
return radius;
}
Circle2D()
{
x = 0;
y = 0;
radius = 1;
}
Circle2D(double a, double b, double r)
{
x = a;
y = b;
radius = r;
}
double getArea()
{
return 3.14 * radius * radius;
}
double getPerimeter()
{
return 2.0 * 3.14 * radius;
}
boolean contains(double x, double y)
{
double temp = (x - this.x) * (x - this.x) + (y - this.y) * (y - this.y);
if(temp < radius * radius) return true;
else return false;
}
boolean contains(Circle2D circle)
{
double temp = (circle.x - x) * (circle.x - x) + (circle.y - y) * (circle.y - y);
if(temp < radius * radius) return true;
else return false;
}
boolean overlaps(Circle2D circle)
{
double temp = (circle.x - x) * (circle.x - x) + (circle.y - y) * (circle.y - y);
if(temp <= radius + circle.radius && temp >= Math.abs(radius - circle.radius)) return true;
else return false;
}
}
// Circle2DTest.java
import java.util.Scanner;
public class Circle2DTest
{
public static void main(String args[])
{
double a1, b1, r1, p, q, a2, b2, r2;
Scanner in = new Scanner(System.in);
System.out.print(\"Enter the centre coordinates of the first circle: \");
a1 = in.nextDouble();
b1 = in.nextDouble();
System.out.print(\"Enter the radius of the first circle: \");
r1 = in.nextDouble();
Circle2D circle1 = new Circle2D(a1, b1, r1);
System.out.println(\"Area = \" + circle1.getArea());
System.out.println(\"Perimeter = \" + circle1.getPerimeter());
System.out.print(\"\ Enter the coordinates of a point: \");
p = in.nextDouble();
q = in.nextDouble();
if(circle1.contains(p, q)) System.out.println(\"The point is inside the Circle\");
else System.out.println(\"The point is outside the Circle\");
System.out.print(\"\ Enter the centre coordinates of the second circle: \");
a2 = in.nextDouble();
b2 = in.nextDouble();
System.out.print(\"Enter the radius of the second circle: \");
r2 = in.nextDouble();
Circle2D circle2 = new Circle2D(a2, b2, r2);
if(circle1.contains(circle2)) System.out.println(\"The second circle is inside the first circle\");
else System.out.println(\"The second circle is outside the first circle\");
if(circle1.overlaps(circle2)) System.out.println(\"\ The second overlaps the first circle\");
else System.out.println(\"\ The second circle does not overlap the first circle\");
}
}
/*
output:
Enter the centre coordinates of the first circle: -5 6
Enter the radius of the first circle: 8
Area = 200.96
Perimeter = 50.24
Enter the coordinates of a point: 4 5
The point is outside the Circle
Enter the centre coordinates of the second circle: 0 1
Enter the radius of the second circle: 9
The second circle is inside the first circle
The second circle does not overlap the first circle
*/

