Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.5 kB
2
Indexable
Never
public class Rectangle {
    int x1;
    int x2;
    int y1;
    int y2;
    //x1 = левая, x2 = правая
    //y1 = нижняя, y2 = верхняя

    int xCenter = (x1+x2)/2;
    int yCenter = (y1+y2)/2;

    public Rectangle(int x1, int x2, int y1, int y2) {
        this.x1 = x1;
        this.x2 = x2;
        this.y1 = y1;
        this.y2 = y2;
    }

    public int getX1() {
        return x1;
    }

    public void setX1(int x1) {
        this.x1 = x1;
    }

    public int getX2() {
        return x2;
    }

    public void setX2(int x2) {
        this.x2 = x2;
    }

    public int getY1() {
        return y1;
    }

    public void setY1(int y1) {
        this.y1 = y1;
    }

    public int getY2() {
        return y2;
    }

    public void setY2(int y2) {
        this.y2 = y2;
    }

    public int getxCenter() {
        return xCenter;
    }

    public void setxCenter(int xCenter) {
        this.xCenter = xCenter;
    }

    public int getyCenter() {
        return yCenter;
    }

    public void setyCenter(int yCenter) {
        this.yCenter = yCenter;
    }

    public double getArea(){
        return Math.abs(x1-x2)*Math.abs(y1-y2);
    }

    public double getPerimeter(){
        return (Math.abs(x1-x2) + Math.abs(y1-y2))*2;
    }

    public double getDistanceToTheCenterOf(Rectangle anotherRectangle){
        return Math.sqrt(Math.pow(x2-x1, 2) + Math.pow(y2-y1,2));
    }
}// AB = √(xb - xa)2 + (yb - ya)2