Skip to content

Commit 5a2cb82

Browse files
committed
Added surface area calculation for pyramid
1 parent d5289b9 commit 5a2cb82

File tree

1 file changed

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

1 file changed

+21
-0
lines changed

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

Lines changed: 21 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
*/
@@ -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+

0 commit comments

Comments
 (0)