From ff61ddbdbcf527eb4b65f5cfa1e19017c48a80f3 Mon Sep 17 00:00:00 2001 From: Joshua Slack Date: Thu, 29 Oct 2026 15:05:37 -0400 Subject: [PATCH] =?UTF-8?q?Added=20surface=20area=20calculation=20for=20py?= =?UTF-8?q?ramid=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../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..b016b69712bc 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -7,6 +7,25 @@ public final class Area { private Area() { } + /** + * 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; + } + /** * String of IllegalArgumentException for radius */