Skip to content

Commit 2750ba1

Browse files
committed
Added surface area calculation for pyramid
1 parent 03bb8ee commit 2750ba1

File tree

1 file changed

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

1 file changed

+13
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,17 @@ public static double surfaceAreaCone(final double radius, final double height) {
192192
}
193193
return Math.PI * radius * (radius + Math.pow(height * height + radius * radius, 0.5));
194194
}
195+
196+
//Calculate the surface area of a pyramid with a square base
197+
public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) {
198+
if (sideLength <= 0) {
199+
throw new IllegalArgumentException("Must be a positive sideLength");
200+
}
201+
if (slantHeight <= 0) {
202+
throw new IllegalArgumentException("Must be a positive slantHeight");
203+
}
204+
double baseArea = sideLength * sideLength;
205+
double lateralSurfaceArea = 2 * sideLength * slantHeight;
206+
return baseArea + lateralSurfaceArea;
207+
}
195208
}

0 commit comments

Comments
 (0)