From 53a7e1810e5044204a3ed67fbd98da35ce4d3392 Mon Sep 17 00:00:00 2001 From: Mohamed Hassan Rezk Sammour Date: Thu, 29 Oct 2026 15:12:49 -0400 Subject: [PATCH 1/3] Added surface area calc for pyramid --- .../java/com/thealgorithms/maths/Area.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index 84fc67159379..8f5de908922e 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -232,4 +232,24 @@ public static double surfaceAreaCone(final double radius, final double height) { } return Math.PI * radius * (radius + Math.pow(height * height + radius * radius, 0.5)); } + + + /** +* 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; +} } From c71f2d13907a3de0214c2fa3f4f4e5d4f5f1406e Mon Sep 17 00:00:00 2001 From: Mohamed Hassan Rezk Sammour Date: Thu, 29 Oct 2026 15:15:31 -0400 Subject: [PATCH 2/3] Update Area.java --- src/main/java/com/thealgorithms/maths/Area.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index 8f5de908922e..11969af08b2c 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -243,13 +243,13 @@ public static double surfaceAreaCone(final double radius, final double height) { */ public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) { if (sideLength <= 0) { -throw new IllegalArgumentException("Must be a positive sideLength"); + throw new IllegalArgumentException("Must be a positive sideLength"); } if (slantHeight <= 0) { -throw new IllegalArgumentException("Must be a positive slantHeight"); + throw new IllegalArgumentException("Must be a positive slantHeight"); } -double baseArea = sideLength * sideLength; -double lateralSurfaceArea = 2 * sideLength * slantHeight; -return baseArea + lateralSurfaceArea; + double baseArea = sideLength * sideLength; + double lateralSurfaceArea = 2 * sideLength * slantHeight; + return baseArea + lateralSurfaceArea; } } From 3c86c185129502471544f2d35e8b4795e7f6db4d Mon Sep 17 00:00:00 2001 From: Mohamed Hassan Rezk Sammour Date: Thu, 29 Oct 2026 15:28:48 -0400 Subject: [PATCH 3/3] Update Area.java --- .../java/com/thealgorithms/maths/Area.java | 48 ++++++++----------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index 11969af08b2c..abc69fc2adae 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -76,17 +76,25 @@ 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 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. @@ -235,21 +243,3 @@ public static double surfaceAreaCone(final double radius, final double height) { /** -* 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; -} -}