Skip to content

Commit 4a7b413

Browse files
committed
Added surface area calculation for pyramid
1 parent 873dd97 commit 4a7b413

File tree

1 file changed

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

1 file changed

+14
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,18 @@ 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+
*/
198+
public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) {
199+
if (sideLength <= 0) {
200+
throw new IllegalArgumentException("Must be a positive sideLength");
201+
}
202+
if (slantHeight <= 0) {
203+
throw new IllegalArgumentException("Must be a positive slantHeight");
204+
}
205+
double baseArea = sideLength * sideLength;
206+
double lateralSurfaceArea = 2 * sideLength * slantHeight;
207+
return baseArea + lateralSurfaceArea;
208+
}
195209
}

0 commit comments

Comments
 (0)