From 3dc70da8de22cc7c5702443dce5e9f6afbb542bb Mon Sep 17 00:00:00 2001 From: AaronBoodoosingh14 Date: Fri, 30 Oct 2026 00:21:37 -0400 Subject: [PATCH] added surface area calculation for a pyramid --- .../java/com/thealgorithms/maths/Area.java | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index 84fc67159379..97934b618587 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -35,6 +35,7 @@ public static double surfaceAreaCube(final double sideLength) { return 6 * sideLength * sideLength; } + /** * Calculate the surface area of a cuboid. * @@ -69,24 +70,25 @@ public static double surfaceAreaSphere(final double radius) { return 4 * Math.PI * radius * radius; } - /** - * 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(""); - } - 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 surfae area of a pyramid with a square base. + * + * @param sideLength + * @param slantHeight + * @return + */ + +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.