Question #303856

calculate the area of rectangle a square a triangle by using constructor overloading






Expert's answer

public class Main {
    private int width;
    private int height;

    public Main(int widthOrBase, int height) {
        width = widthOrBase;
        this.height = height;
    }

    public Main(int side) {
        width = side;
        height = side;
    }

    public int rectangleArea() {
        return width * height;
    }

    public int squareArea() {
        return width * height;
    }

    public double triangleArea() {
        return 0.5 * width * height;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS