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

Write a Java program to develop a class Circle2D with the following specificatio

ID: 3718820 • Letter: W

Question

Write a Java program to develop a class Circle2D with the following specifications 1. Class circle2D ?nherits Circle class and implements Colourful nterface 2. The class has three private attributes: color of type string, x, and y (both of type double), x and y attributes specify the center of the circle 3· The class has a Three-argument constructor that sets the value of its x, y, and radius to 4· The class has a zero-argument constructor that sets the value of its instance variables to 5. The class has to implement fillMyColour given values. It should invoke its super-class constructor. their default values. It should invoke its Three-argument constructor in the same class method, which assign the given string value to the color instance variable 6. The class has a private method distance double xl, double yl, double x2, double y2) that returns the distance between (xl.yl) and (x2, y2) Hint: distance between two points-(x2 - x1)2 (y2 -y1)2 7. The class has a public method contains (double xl, double yl) that returns true if (x1, yl) is inside the circle Hint: (xl, yl) is contained in the circle if the distance between (xl, yl) and the center of the circle represented by attributes (xy) less than or equal radius of the circle 8. The class has a public method contains (Circle2D circle1) that returns true if the specified circle! 1s inside this circle. Hint: the current circle contains circle1 if the distance between the two centers of the circles + circle1.radius less than or equal to this.radius. 9. The class has a public method overlaps (Circle2D circle1) that returns true if the specified circle1 overlaps with this circle. Hint: Two circles overlap if the distance between the two centers are less than or equal to this.radius + circlel. radius. 10.Override the Object's toString) method in order to return a string representation of the circle 2D Instance variables as the below format, it should invoke its super class tostring ) method: radius = , area = , perimeter = , center point of the circl e: , color is

Explanation / Answer

Colorful.java

public interface Colorful {
void fillMyColor();
}

______________

Circle2D.java

import java.util.Scanner;

public class Circle2D {

// Declaring instance variables

private String color;

private double x;

private double y;

private double radius;

// Zero argumented constructor

public Circle2D() {

this.x = 0;

this.y = 0;

this.radius = 1.0;

}

// Parameterized constructor

public Circle2D(double x, double y, double radius) {

this.x = x;

this.y = y;

this.radius = radius;

}

// getters and setters

public double getX() {

return this.x;

}

public double getY() {

return this.y;

}

void fillMyColor()

{

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

//Getting the input entered by the user

System.out.print("Enter Color:");

color=sc.next();

}

// This method will calculate the radius of the circle

public double getRadius() {

return this.radius;

}

// This method will calculate the perimeter of the circle

public double getPerimeter() {

return 2 * Math.PI * this.radius;

}

// This method will calculate the area of the circle

public double getArea() {

return Math.PI * (this.radius * this.radius);

}

public boolean contains(double x, double y) {

double d = Math.sqrt(Math.pow((x - this.x), 2)

+ Math.pow((y - this.y), 2));

if (d < this.radius)

return true;

else

return false;

}

public boolean contains(Circle2D circle) {

double d = Math.sqrt(Math.pow((circle.x - this.x), 2)

+ Math.pow((circle.y - this.y), 2));

if (d + circle.radius < this.radius)

return true;

else

return false;

}

public boolean overlaps(Circle2D circle) {

double d = Math.sqrt(Math.pow((circle.x - this.x), 2)

+ Math.pow((circle.y - this.y), 2));

if (d <= circle.radius + this.radius)

return true;

else

return false;

}

@Override

public String toString() {

return "Radius = "+radius+" Area = "+getArea()+" Perimter = "+getPerimeter()+" "+" Center Point of the Circle: ("+x+","+y+")"+" Color is :"+color;

}

}

________________

Test.java

public class Test {

public static void main(String[] args) {

//Creating an instance of Circle2D class

Circle2D c1 = new Circle2D(2, 2, 5.5);

  

c1.fillMyColor();

//Displaying the output

System.out.println("__ Displaying the Circle2D Info __");

System.out.println(c1);

System.out.println("c1.contains(new Circle2D(3,3)): "+c1.contains(3, 3));

System.out.println("c1.contains(new Circle2D(4, 5, 10.5)): " + c1.contains(new Circle2D(4, 5, 10.5)));

System.out.println("c1.overlaps(new Circle2D(3, 5, 2.3)): " + c1.overlaps(new Circle2D(3, 5, 2.3)));

}

}

_________________

Output:

Enter Color:Red
__ Displaying the Circle2D Info __
Radius = 5.5 Area = 95.03317777109125 Perimter = 34.55751918948772 Center Point of the Circle: (2.0,2.0) Color is :Red
c1.contains(new Circle2D(3,3)): true
c1.contains(new Circle2D(4, 5, 10.5)): false
c1.overlaps(new Circle2D(3, 5, 2.3)): true

__________Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote