From 1c59f7a7ba598b243154c0608544f75dfca0156c Mon Sep 17 00:00:00 2001 From: batouldakroub <116668662+batouldakroub@users.noreply.github.com> Date: Wed, 22 Oct 2025 09:53:24 -0400 Subject: [PATCH] Update Area.java --- .../java/com/thealgorithms/maths/Area.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index 7a06fd5e5fa0..0e0fa3999e16 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -34,6 +34,24 @@ public static double surfaceAreaCube(final double sideLength) { } return 6 * sideLength * sideLength; } +/** +* 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 surface area of a sphere.