Вопрос пользователя:
Ответ нейросети:
public class Rectangle {
private int x1;
private int y1;
private int x2;
private int y2;
public Rectangle(int x1, int y1, int x2, int y2) {
if (x1 < 0 || y1 < 0 || x2 < 0 || y2 < 0) {
throw new IllegalArgumentException("Coordinates must be in the first quadrant");
}
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
public int getX1() {
return x1;
}
public int getY1() {
return y1;
}
public int getX2() {
return x2;
}
public int getY2() {
return y2;
}
public int getWidth() {
return x2 - x1;
}
public int getHeight() {
return y2 - y1;
}
public int getArea() {
return getWidth() * getHeight();
}
public int getPerimeter() {
return 2 * (getWidth() + getHeight());
}
public boolean isSquare() {
return getWidth() == getHeight();
}
public void move(int dx, int dy) {
x1 += dx;
y1 += dy;
x2 += dx;
y2 += dy;
}
public void resize(int dw, int dh) {
x2 += dw;
y2 += dh;
}
public static void main(String[] args) {
Rectangle rectangle = new Rectangle(1, 2, 5, 7);
System.out.println("Width: " + rectangle.getWidth());
System.out.println("Height: " + rectangle.getHeight());
System.out.println("Area: " + rectangle.getArea());
System.out.println("Perimeter: " + rectangle.getPerimeter());
System.out.println("Is square: " + rectangle.isSquare());
rectangle.move(3, 4);
System.out.println("New coordinates: (" + rectangle.getX1() + ", " + rectangle.getY1() + "), (" + rectangle.getX2() + ", " + rectangle.getY2() + ")");
rectangle.resize(2, 3);
System.out.println("New width: " + rectangle.getWidth());
System.out.println("New height: " + rectangle.getHeight());
}
}
Напишите нам, если в вопросе есть ваши персональные данные ([email protected])
Обратите внимание: ответы, предоставляемые искусственным интеллектом, могут не всегда быть точными. Не рассчитывайте на них в критически важных областях, таких как медицина, юриспруденция, финансы или в вопросах, связанных с безопасностью. Для важных решений всегда обращайтесь к квалифицированным специалистам. Администрация сайта не несет ответственности за контент, сгенерированный автоматически.