Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.0 kB
3
Indexable
Never
package labp4;

public class Geometry {

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

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

   
    public static double calculateArea(double base, double height, String shape) {
        if ("triangle".equalsIgnoreCase(shape)) {
            return 0.5 * base * height;
        } else {
            System.out.println("Invalid shape specified for triangle area calculation.");
            return 0.0;
        }
    }

    public static void main(String[] args) {
  
        double circleArea = Geometry.calculateArea(5.0);
        System.out.println("Area of the circle: " + circleArea);

        double rectangleArea = Geometry.calculateArea(4.0, 6.0);
        System.out.println("Area of the rectangle: " + rectangleArea);

        double triangleArea = Geometry.calculateArea(3.0, 4.0, "triangle");
        System.out.println("Area of the triangle: " + triangleArea);
    }
}
Leave a Comment