Skip to content

Commit cc6c2fd

Browse files
committed
Added surface area calculation for pyramid
1 parent 8930369 commit cc6c2fd

File tree

1 file changed

+19
-0
lines changed
  • src/main/java/com/thealgorithms/maths

1 file changed

+19
-0
lines changed

src/main/java/com/thealgorithms/maths/Area.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff 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
*/

0 commit comments

Comments
 (0)