CCCPaste

Задача 2. Конструкторы и перегрузка

public class Rectangle {
    private double width;
    private double height;

    public Rectangle(double width, double height) {
        this.width = width;
        this.height = height;
    }
    public Rectangle(double side){
        this(side,side);
    }
    public Rectangle(){
        this(1.0);
    }
    public double area(){
        return width * height;
    }

    public double getWidth() {
        return width;
    }

    public double getHeight() {
        return height;
    }
}

public class Test {
    public static void main(String[] args) {
    Rectangle rect1 = new Rectangle(5.0, 3.0);
        Rectangle rect2 = new Rectangle(4.0);
        Rectangle rect3 = new Rectangle();

        System.out.println("1-й прямоугольник " + rect1.getWidth() + "x" + rect1.getHeight()+". плошадь = " + rect1.area());
        System.out.println("2-й прямоугольник " + rect2.getWidth() + "x" + rect2.getHeight()+". плошадь = " + rect2.area());
        System.out.println("3-й прямоугольник " + rect3.getWidth() + "x" + rect3.getHeight()+". плошадь = " + rect3.area());
	}
}