Answer to Question #304949 in Java | JSP | JSF for sandyJay

Question #304949

Write a class that has three overloaded methods for calculating the areas of the following geometric shapes:

 

•    Circle

•    Rectangle

•    Cylinder

 

Here are the formulae for calculating the area of the respective shapes:


Shape: Circle

Area Formula: A = πr2

Notes: π is Math.PI and r is the circle’s radius

Shape: Rectangle

Area Formula: Area = Width * Height

Shape: Cylinder

Area Formula: Area = 2πrh + 2πr2

Notes: π is Math.PIand r is the radius of the cylinder’s base h is the cylinder’s height


1
Expert's answer
2022-03-03T09:58:51-0500
package com.task;

public abstract class Shape {

    public static void main(String[] args) {
   // write your code here
    }

    public abstract double area();

}
package com.task;

public class Circle extends Shape{

    private double radius;

    @Override
    public double area() {
        return 3.14*radius*radius;
    }

}
package com.task;

public class Rectangle extends Shape {

    private double height;
    private double width;

    @Override
    public double area() {
        return height*width;
    }

}
package com.task;

public class Cylinder extends Shape {

    private double radius;
    private double height;

    @Override
    public double area() {
        return 2*3.14*radius*height+2*3.14*radius*radius;
    }

}

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