File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
src/main/java/com/thealgorithms/maths Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,25 @@ private Area() {
2121 * String of IllegalArgumentException for base
2222 */
2323 private static final String POSITIVE_BASE = "Must be a positive base" ;
24+
25+ /**
26+ * Calculate the surface area of a pyramid with a square base.
27+ *
28+ * @param sideLength side length of the square base
29+ * @param slantHeight slant height of the pyramid
30+ * @return surface area of the given pyramid
31+ */
32+ public static double surfaceAreaPyramid (final double sideLength , final double slantHeight ) {
33+ if (sideLength <= 0 ) {
34+ throw new IllegalArgumentException ("Must be a positive sideLength" );
35+ }
36+ if (slantHeight <= 0 ) {
37+ throw new IllegalArgumentException ("Must be a positive slantHeight" );
38+ }
39+ double baseArea = sideLength * sideLength ;
40+ double lateralSurfaceArea = 2 * sideLength * slantHeight ;
41+ return baseArea + lateralSurfaceArea ;
42+ }
2443
2544 /**
2645 * Calculate the surface area of a cube.
You can’t perform that action at this time.
0 commit comments