Question
please make uml class diagram and flowchart and pseudocode public class Circle2D { //data fields private double x; private double y; private double radius; //no-arg
please make uml class diagram and flowchart and pseudocode
public class Circle2D {
//data fields
private double x;
private double y;
private double radius;
//no-arg constructor
public Circle2D()
{
x = 0;
y = 0;
radius = 1;
}
//parameterized constructor
Circle2D(double x, double y, double radius)
{
this.x = x;
this.y = y;
this.radius = radius;
}
//method that gets the value of x
public double getX()
{
return x;
}
//method that gets the value of y
public double getY()
{
return y;
}
//method that gets the radius
public double getRadius()
{
return radius;
}
//method that returns the area of the circle
public double getArea()
{
return Math.PI * radius * radius;
}
//method that returns the perimeter of the circle
public double getPerimeter()
{
return 2 * Math.PI * radius;
}
//method that returns true if the specified point(x, y) is inside this circle
public boolean contains(double x, double y)
{
//calculate the distance between the two circles
double distance = Math.sqrt(Math.pow(x - this.x, 2) + Math.pow(y - this.y, 2));
//check and return whether circle contains this circle
if (distance < radius)
return true;
else
return false;
}
//method that returns true if specified circle is inside this circle
public boolean contains(Circle2D circle)
{
//calculate the distance between the two circles
double distance = Math.sqrt(Math.pow(circle.getX() - this.x, 2) + Math.pow(circle.getY() - this.y, 2));
//check and return whether circle contains this circle
if (distance <= Math.abs(radius - circle.getRadius()))
return true;
else
return false;
}
//method that returns true if specified circle overlaps this circle
public boolean overlaps(Circle2D circle)
{
//calculate the distance between the two circles
double distance = Math.sqrt(Math.pow(circle.getX() - this.x, 2) + Math.pow(circle.getY() - this.y, 2));
//check and return whether circle overlaps this circle
if(distance <= radius + circle.getRadius())
return true;
else
return false;
}
}
class TestCircle2D {
public static void main(String[] args) {
//create an object to the circle class
Circle2D circle = new Circle2D(2, 2, 5.5);
//display the area of the circle using getArea method
System.out.println("Area is " + circle.getArea());
//display the area of the circle using getPerimeter method
System.out.println("Perimeter is " + circle.getPerimeter());
//check if circle contains otherCircle1
System.out.println("does c1 contain points:"+circle.contains(3,3));
//create another circle
Circle2D otherCircle2 = new Circle2D(4, 5, 10.5);
//check if circle contains otherCircle2
System.out.println("does c1 contain c2:"+circle.contains(otherCircle2));
//create another circle
Circle2D otherCircle3 = new Circle2D(3,5,2.3);
//check if circle overlaps otherCircle3
System.out.println("does c1 overlap:"+ circle.overlaps(otherCircle3));
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started