From e480caac41cae99e696e7f8a96a04ea73f5c35b7 Mon Sep 17 00:00:00 2001 From: Maria-2703 Date: Thu, 29 Oct 2026 14:53:23 -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 84fc67159379..01cd3454fe6c 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -232,4 +232,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 09094348f1e47d1a6c57d9ef484e19337940c51b Mon Sep 17 00:00:00 2001 From: Maria-2703 Date: Thu, 29 Oct 2026 15:04:20 -0400 Subject: [PATCH 2/3] added surface area calculation for pyramid --- .../java/com/thealgorithms/maths/Area.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index 01cd3454fe6c..b6dfb0f24f52 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -232,23 +232,5 @@ 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 b9d194ef51df3088e735d6d0d3a2b71c54e0a8c0 Mon Sep 17 00:00:00 2001 From: Maria-2703 Date: Thu, 29 Oct 2026 15:12:24 -0400 Subject: [PATCH 3/3] added surface area calculation for pyramid --- .../java/com/thealgorithms/maths/Area.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index b6dfb0f24f52..20c17ff306e3 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -69,25 +69,6 @@ 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 area of a rectangle. * @@ -233,4 +214,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(""); + } + 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; + } + }