Answer to Question #308364 in Java | JSP | JSF for junior

Question #308364

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

 

•    Circle

•    Rectangle

•    Cylinder 


1
Expert's answer
2022-03-09T06:39:25-0500


class Shape {


	public double calculateArea(double radius) {
		return Math.PI * radius * radius;
	}


	public double calculateArea(double width, double height) {
		return width * height;
	}


	public double calculateArea(double radius, double height, int k) {
		return 2 * Math.PI * radius * (radius + height);
	}


}


class App {


	public static void main(String[] args) {
		Shape s = new Shape();


		System.out.println("The area of circle is: " + s.calculateArea(5));
		System.out.println("The area of rectangle is: " + s.calculateArea(5, 4));
		System.out.println("The area of cylinder is: " + s.calculateArea(5, 4, 5));


	}
}

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