From 6e3eb3c58cf0a2bfff7b1d1f0abd035f3994da4a Mon Sep 17 00:00:00 2001 From: Cmelvank <116571652+Cmelvank@users.noreply.github.com> Date: Mon, 20 Oct 2025 15:12:18 -0400 Subject: [PATCH] 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 7a06fd5e5fa0..49534a4f8a10 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -21,6 +21,25 @@ private Area() { * String of IllegalArgumentException for base */ private static final String POSITIVE_BASE = "Must be a positive base"; + + /** + * 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 surface area of a cube.