From f075515950d1f5c72ce628ca55f3848ad029e5d0 Mon Sep 17 00:00:00 2001 From: Makrus12345 Date: Tue, 21 Oct 2025 22:21:14 -0400 Subject: [PATCH 1/2] Added surfaceAreaPyramid_v4 with improved comments and validation --- .../java/com/thealgorithms/maths/Area.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index 7a06fd5e5fa0..c5f0bfc5171c 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -192,4 +192,31 @@ public static double surfaceAreaCone(final double radius, final double height) { } return Math.PI * radius * (radius + Math.pow(height * height + radius * radius, 0.5)); } + /** + * Calculates the surface area of a pyramid with a square base. + * This includes both the base and the four triangular faces. + * + * @param sideLength the length of one side of the square base + * @param slantHeight the slant height of the pyramid + * @return the total surface area of the pyramid + * @throws IllegalArgumentException if any parameter is non-positive + */ + public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) { + // Validation checks to ensure inputs are physically valid + if (sideLength <= 0) { + throw new IllegalArgumentException("Side length must be a positive number"); + } + if (slantHeight <= 0) { + throw new IllegalArgumentException("Slant height must be a positive number"); + } + + // Base area (square) = side² + double baseArea = sideLength * sideLength; + + // Lateral area = 2 × side × slant height + double lateralSurfaceArea = 2 * sideLength * slantHeight; + + // Combine base and lateral areas for total surface area + return baseArea + lateralSurfaceArea; + } } From 0b2841e39ca1a82e07e8d2fb428250b364edea6a Mon Sep 17 00:00:00 2001 From: Makrus12345 Date: Tue, 21 Oct 2025 22:44:14 -0400 Subject: [PATCH 2/2] Fixed indentation to pass clang-format --- src/main/java/com/thealgorithms/maths/Area.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index c5f0bfc5171c..addeef82465c 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -192,7 +192,7 @@ public static double surfaceAreaCone(final double radius, final double height) { } return Math.PI * radius * (radius + Math.pow(height * height + radius * radius, 0.5)); } - /** + /** * Calculates the surface area of a pyramid with a square base. * This includes both the base and the four triangular faces. *