From 19888cec55f4d4e54c1b916b65466f6300896cae Mon Sep 17 00:00:00 2001 From: MaxStroikin Date: Tue, 21 Oct 2025 12:54:44 -0400 Subject: [PATCH] commit --- .../java/com/thealgorithms/maths/Area.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index 7a06fd5e5fa0..5561054bf2c0 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -1,3 +1,5 @@ + + package com.thealgorithms.maths; /** @@ -129,6 +131,26 @@ public static double surfaceAreaParallelogram(final double base, final double he return base * 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; +} + + /** * Calculate the area of a trapezium. *