From 47c7e12584e38a70845f66e282044f9ebaae2efa Mon Sep 17 00:00:00 2001 From: Shane Date: Thu, 29 Oct 2026 15:12:44 -0400 Subject: [PATCH 1/2] Added surface area calculation for pyramid --- .../java/com/thealgorithms/maths/Area.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index 84fc67159379..a7780154f050 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -232,4 +232,23 @@ 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 + * @param slantHeight + * @return surface area of the 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 0161b6094c90b2c788f3985af3379af165093d04 Mon Sep 17 00:00:00 2001 From: Shane Date: Thu, 29 Oct 2026 15:26:44 -0400 Subject: [PATCH 2/2] Removed duplicate square pyramid area function --- src/main/java/com/thealgorithms/maths/Area.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index a7780154f050..cb5fac6122a3 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -76,6 +76,7 @@ public static double surfaceAreaSphere(final double radius) { * @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(""); @@ -87,6 +88,7 @@ public static double surfaceAreaPyramid(final double sideLength, final double sl double lateralSurfaceArea = 2 * sideLength * slantHeight; return baseArea + lateralSurfaceArea; } + */ /** * Calculate the area of a rectangle.