From cbd67c9e45343129d47c300b95c0d096258c3f3c Mon Sep 17 00:00:00 2001 From: maria Date: Thu, 29 Oct 2026 19:54:08 -0400 Subject: [PATCH] Added surface area calculation for pyramid --- .../java/com/thealgorithms/maths/Area.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index 84fc67159379..1cb9c55a750f 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -76,6 +76,10 @@ public static double surfaceAreaSphere(final double radius) { * @param slantHeight slant height of the pyramid * @return surface area of the given pyramid */ + + + /* + commenting out this section to replace it with new code: public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) { if (sideLength <= 0) { throw new IllegalArgumentException(""); @@ -87,6 +91,27 @@ public static double surfaceAreaPyramid(final double sideLength, final double sl double lateralSurfaceArea = 2 * sideLength * slantHeight; return baseArea + lateralSurfaceArea; } +*/ + /// added code chunk below: + /** + * 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 rectangle.