From cc6c2fde1fafa1a672083f5c51cb5a0be132c877 Mon Sep 17 00:00:00 2001 From: ritwij Date: Wed, 22 Oct 2025 08:07:25 -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..7b3a246b57a8 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 */