Skip to content

Commit fd30fdf

Browse files
authored
Update Area.java
1 parent 8930369 commit fd30fdf

File tree

1 file changed

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

1 file changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@
66
public final class Area {
77
private Area() {
88
}
9+
/**
10+
* Calculate the surface area of a pyramid with a square base.
11+
*
12+
* @param sideLength side length of the square base
13+
* @param slantHeight slant height of the pyramid
14+
* @return surface area of the given pyramid
15+
*/
16+
public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) {
17+
if (sideLength <= 0) {
18+
throw new IllegalArgumentException("Must be a positive sideLength");
19+
}
20+
if (slantHeight <= 0) {
21+
throw new IllegalArgumentException("Must be a positive slantHeight");
22+
}
23+
double baseArea = sideLength * sideLength;
24+
double lateralSurfaceArea = 2 * sideLength * slantHeight;
25+
return baseArea + lateralSurfaceArea;
26+
}
927

1028
/**
1129
* String of IllegalArgumentException for radius

0 commit comments

Comments
 (0)