Question: //---------public class MyCircles----------//// public class MyCircles { ArrayList circles = new ArrayList(); public MyCircles() { } public void addCircle2D(Circle2D circle, String color) { circles.add(circle); }

 //---------public class MyCircles----------//// public class MyCircles { ArrayList circles = new

//---------public class MyCircles----------////

public class MyCircles {

ArrayList circles = new ArrayList();

public MyCircles() {

}

public void addCircle2D(Circle2D circle, String color) {

circles.add(circle);

}

public void readFromFile(String fileName) throws FileNotFoundException {

Scanner scanner = new Scanner(new FileReader(fileName));

// Read all the lines

while(scanner.hasNext()) {

// Read a line

double x, y, radius;

String color;

x = scanner.nextDouble();

y = scanner.nextDouble();

radius = scanner.nextDouble();

color = scanner.next();

// create circle object

Circle2D circle = new Circle2D(x, y, radius, color);

// Add circle to the list

addCircle2D(circle, color);

}

}

public void printAll() {

if(circles.isEmpty()) {

System.out.println("NO Shapes are available");

} else {

for (int i = 0; i

System.out.println(circles.get(i));

}

}

}

public static class Circle2D {

public final double x, y, radius;

public final String color;

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

this.x = x;

this.y = y;

this.radius = radius;

this.color = color;

}

@Override

public String toString() {

return String.format("Circle: x = %.2f, y = %.2f, radius = %.2f, %s", x, y, radius, color);

}

}

public static void main (String[] args) throws FileNotFoundException {

MyCircles myCircles = new MyCircles();

System.out.println("Initialling calling printAll method:");

myCircles.printAll();

myCircles.readFromFile("circles.txt");

System.out.println(" Calling printAll after filling data from file:");

myCircles.printAll();

}

}

6. 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 7. 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 6. 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 7. 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

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!