Question: Develope A class that 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

Develope A class that 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.

/////Public public class MyCircles Is Below /////

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.util.ArrayList;

import java.util.Scanner;

////This is MyCircles class///

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 < circles.size(); 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();

}

}

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!