From 130147fe84eccdd757a4be75ff22edb54b319dc8 Mon Sep 17 00:00:00 2001 From: jaspinkl Date: Mon, 20 Oct 2025 10:53:11 -0400 Subject: [PATCH] Added surface area calculations --- .../java/com/thealgorithms/maths/Area.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index 7a06fd5e5fa0..97156916c188 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -149,7 +149,25 @@ public static double surfaceAreaTrapezium(final double base1, final double base2 } return (base1 + base2) * height / 2; } + /** + * 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; + } /** * Calculate the area of a circle. *