From 41311ab4be80973edd87cb3458605ff4dfeabad4 Mon Sep 17 00:00:00 2001 From: Esteban Ramirez Date: Thu, 29 Oct 2026 16:18:45 -0400 Subject: [PATCH] feat: implement algorithm changes --- .../java/com/thealgorithms/maths/Area.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index 84fc67159379..51bc05f43d0d 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -76,17 +76,7 @@ public static double surfaceAreaSphere(final double radius) { * @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(""); - } - if (slantHeight <= 0) { - throw new IllegalArgumentException("slant height must be greater than 0"); - } - double baseArea = sideLength * sideLength; - double lateralSurfaceArea = 2 * sideLength * slantHeight; - return baseArea + lateralSurfaceArea; - } + /** * Calculate the area of a rectangle. @@ -232,4 +222,15 @@ public static double surfaceAreaCone(final double radius, final double height) { } return Math.PI * radius * (radius + Math.pow(height * height + radius * radius, 0.5)); } -} + 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; + + }