From 47678f02c124351327832bb0de471d86cdad1fd9 Mon Sep 17 00:00:00 2001 From: Daniel Murillo Date: Wed, 22 Oct 2025 01:08:20 -0400 Subject: [PATCH 1/3] Added surface area calculation for pyramid --- .../java/com/thealgorithms/maths/Area.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index 7a06fd5e5fa0..b82aebcf88d1 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -192,4 +192,23 @@ 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 edc5e1cd73a37abaee8319e251673ef3fbfd49fa Mon Sep 17 00:00:00 2001 From: Daniel Murillo Date: Wed, 22 Oct 2025 01:10:33 -0400 Subject: [PATCH 2/3] Redo --- .../java/com/thealgorithms/maths/Area.java | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index b82aebcf88d1..7a06fd5e5fa0 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -192,23 +192,4 @@ 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 605a2c54c64ba39e935cdb9bd5c38722cc68d124 Mon Sep 17 00:00:00 2001 From: Daniel Murillo Date: Wed, 22 Oct 2025 01:20:19 -0400 Subject: [PATCH 3/3] Added surface area calculation for pyramid --- .../java/com/thealgorithms/maths/Area.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index 7a06fd5e5fa0..b82aebcf88d1 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -192,4 +192,23 @@ 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; + } }