Untitled
unknown
plain_text
14 days ago
1.2 kB
2
Indexable
Never
public class AreaCalculator { // Method to calculate the area of a circle public double area(double radius) { return Math.PI * radius * radius; } // Method to calculate the area of a rectangle public double area(double length, double width) { return length * width; } // Method to calculate the area of a square public double area(int side) { return side * side; } public static void main(String[] args) { AreaCalculator calculator = new AreaCalculator(); // Calculate area of a circle double circleRadius = 5.0; double circleArea = calculator.area(circleRadius); System.out.println("Area of the circle: " + circleArea); // Calculate area of a rectangle double rectangleLength = 4.0; double rectangleWidth = 6.0; double rectangleArea = calculator.area(rectangleLength, rectangleWidth); System.out.println("Area of the rectangle: " + rectangleArea); // Calculate area of a square int squareSide = 3; double squareArea = calculator.area(squareSide); System.out.println("Area of the square: " + squareArea); } }
Leave a Comment