File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
src/main/java/com/thealgorithms/maths Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,25 @@ public final class Area {
77 private Area () {
88 }
99
10+ /**
11+ * Calculate the surface area of a pyramid with a square base.
12+ *
13+ * @param sideLength side length of the square base
14+ * @param slantHeight slant height of the pyramid
15+ * @return surface area of the given pyramid
16+ */
17+ public static double surfaceAreaPyramid (final double sideLength , final double slantHeight ) {
18+ if (sideLength <= 0 ) {
19+ throw new IllegalArgumentException ("Must be a positive sideLength" );
20+ }
21+ if (slantHeight <= 0 ) {
22+ throw new IllegalArgumentException ("Must be a positive slantHeight" );
23+ }
24+ double baseArea = sideLength * sideLength ;
25+ double lateralSurfaceArea = 2 * sideLength * slantHeight ;
26+ return baseArea + lateralSurfaceArea ;
27+ }
28+
1029 /**
1130 * String of IllegalArgumentException for radius
1231 */
@@ -193,3 +212,5 @@ public static double surfaceAreaCone(final double radius, final double height) {
193212 return Math .PI * radius * (radius + Math .pow (height * height + radius * radius , 0.5 ));
194213 }
195214}
215+
216+
You can’t perform that action at this time.
0 commit comments