Вопрос пользователя:
Ответ нейросети:
class Point {
private int x;
private int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
class Circle {
private Point center;
private int radius;
public Circle(Point center, int radius) {
this.center = center;
this.radius = radius;
}
public int getRadius() {
return radius;
}
public double getSquare() throws NegativeRadiusException {
if (radius < 0) {
throw new NegativeRadiusException("Radius cannot be negative");
}
return Math.PI * radius * radius;
}
}
class NegativeRadiusException extends Exception {
public NegativeRadiusException(String message) {
super(message);
}
}
class App {
public static void printSquare(Circle circle) {
try {
int square = (int) Math.round(circle.getSquare());
System.out.println("Square of the circle: " + square);
} catch (NegativeRadiusException e) {
System.out.println("Failed to calculate square: " + e.getMessage());
} finally {
System.out.println("Calculation finished");
}
}
}
public class Main {
public static void main(String[] args) {
Point center = new Point(0, 0);
Circle circle = new Circle(center, 5);
App.printSquare(circle);
Circle circle2 = new Circle(center, -2);
App.printSquare(circle2);
}
}
Напишите нам, если в вопросе есть ваши персональные данные ([email protected])
Обратите внимание: ответы, предоставляемые искусственным интеллектом, могут не всегда быть точными. Не рассчитывайте на них в критически важных областях, таких как медицина, юриспруденция, финансы или в вопросах, связанных с безопасностью. Для важных решений всегда обращайтесь к квалифицированным специалистам. Администрация сайта не несет ответственности за контент, сгенерированный автоматически.