Answer to Question #303856 in Java | JSP | JSF for anvi

Question #303856

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






1
Expert's answer
2022-02-28T13:53:31-0500
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS