diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index 84fc67159379..8d7871e1d57f 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -76,15 +76,22 @@ 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) { + public static double surfaceAreaPyramid( + final double sideLength, final double slantHeight) { + if (sideLength <= 0) { - throw new IllegalArgumentException(""); + throw new IllegalArgumentException( + "side length must be greater than 0"); } + if (slantHeight <= 0) { - throw new IllegalArgumentException("slant height must be greater than 0"); + throw new IllegalArgumentException( + "slant height must be greater than 0"); } - double baseArea = sideLength * sideLength; - double lateralSurfaceArea = 2 * sideLength * slantHeight; + + final double baseArea = sideLength * sideLength; + final double lateralSurfaceArea = 2 * sideLength * slantHeight; + return baseArea + lateralSurfaceArea; }