Question: Develop a public class MyCircles to the following specifications: The class has a private instance ArrayList, which represent a collection of Circle2D. The class has

Develop a public class MyCircles to the following specifications:

The class has a private instance ArrayList, which represent a collection of Circle2D.

The class has a zero-argument constructor that creates and initializes the ArrayList instance object.

The class has a public method void addCircle2D (Object, String) which is used to add an instance object of Circle2D into the ArrayList. The String represents the name of the color that will fill the circle2D object.

The class has the method readFromFile (String). It reads from a text file which its name given as a string argument of the method. Then fills the ArrayList collection with the values of the circle2D instance objects. Hint: Each line in the file has 4 values representing x, y, and radius of type double consequently, followed by a string value represent the color.

The class has the method printAll(). It displays either a string representing each element in the ArrayList (one per line) or a string message that NO Shapes are available.

The class has the method check_Overlaps_Contains(), which displays which circles of the ArrayList are overlapped with each other, or contained in each other. The method should print a message format as follows:

Checking Overlaps and Contains Circle: 0 with red color: Overlaps with Circle:1 that has yellow color.

Contains Circle:2 that has blue color. Circle: 1 with yellow color: Overlaps with Circle:0 that has red color.

Contains Circle:0 that has red color. Overlaps with Circle:2 that has blue color.

Hint: 0 and 1 represent the index of the objects in the ArrayList.

The class has the method check_contains_point(double x, double y), which displays which circles of the ArrayList contains point(x,y). The method should print a message format as follows:

The following circles containing the Point (, .) **********************************************

Circle: 0 with red color.

.

Circle2D Class:

public abstract class Circle2D extends Circle implements Colourful{

private String color; private double x, y;

public Circle2D(double r,String color, double x, double y)

{

super(r); this.x = x; this.y = y; this.color = color; }

public void fillMyColor(String c)

{ color = c; }

private double distance(double x1, double x2, double y1, double y2)

{

return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2-y1,2)); } public boolean contains(double x1, double y1) { return distance(x1,y1,x,y) < super.getRadius(); }

public boolean contains(Circle2D c1) {

return(Math.abs(distance(c1.x,c1.y,x,y))+super.getRadius())<=c1.getRadius();

}

public boolean overlaps(Circle2D c1) {

return Math.abs(distance(c1.x,c1.y,x,y))+c1.getRadius()<= super.getRadius(); }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!