Skip to content

Commit 130147f

Browse files
committed
Added surface area calculations
1 parent d5289b9 commit 130147f

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
@@ -149,7 +149,25 @@ public static double surfaceAreaTrapezium(final double base1, final double base2
149149
}
150150
return (base1 + base2) * height / 2;
151151
}
152+
/**
153+
* Calculate the surface area of a pyramid with a square base.
154+
*
155+
* @param sideLength side length of the square base
156+
* @param slantHeight slant height of the pyramid
157+
* @return surface area of the given pyramid
152158
159+
*/
160+
public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) {
161+
if (sideLength <= 0) {
162+
throw new IllegalArgumentException("Must be a positive sideLength");
163+
}
164+
if (slantHeight <= 0) {
165+
throw new IllegalArgumentException("Must be a positive slantHeight");
166+
}
167+
double baseArea = sideLength * sideLength;
168+
double lateralSurfaceArea = 2 * sideLength * slantHeight;
169+
return baseArea + lateralSurfaceArea;
170+
}
153171
/**
154172
* Calculate the area of a circle.
155173
*

0 commit comments

Comments
 (0)