From dc62cf6fdb6bd25d0a6d2f56f8cd99722c7a0077 Mon Sep 17 00:00:00 2001 From: KushShastri Date: Wed, 30 Oct 2024 01:13:36 -0400 Subject: [PATCH 1/2] made change --- .../java/com/thealgorithms/maths/Area.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index 7a06fd5e5fa0..83225c32222a 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -192,4 +192,28 @@ public static double surfaceAreaCone(final double radius, final double height) { } return Math.PI * radius * (radius + Math.pow(height * height + radius * radius, 0.5)); } + + /** + * Calculate the surface area of a pyramid with a square base. + * + * @param sideLength side length of the square base + * @param slantHeight slant height of the pyramid + * @return surface area of the given pyramid + */ + public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) { + if (sideLength <= 0) { + throw new IllegalArgumentException("Must be a positive sideLength"); + } + if (slantHeight <= 0) { + throw new IllegalArgumentException("Must be a positive slantHeight"); + } + double baseArea = sideLength * sideLength; + double lateralSurfaceArea = 2 * sideLength * slantHeight; + return baseArea + lateralSurfaceArea; + } + + + + + } From d6d0c7269800277bdbf57ee3159569c20712db3b Mon Sep 17 00:00:00 2001 From: KushShastri Date: Wed, 30 Oct 2024 01:25:02 -0400 Subject: [PATCH 2/2] made change again --- src/main/java/com/thealgorithms/maths/Area.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index 83225c32222a..9509507798b8 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -202,6 +202,7 @@ public static double surfaceAreaCone(final double radius, final double height) { */ public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) { if (sideLength <= 0) { + throw new IllegalArgumentException("Must be a positive sideLength"); } if (slantHeight <= 0) {