File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
src/main/java/com/thealgorithms/maths Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,24 @@ public static double surfaceAreaSphere(final double radius) {
4747 }
4848 return 4 * Math .PI * radius * radius ;
4949 }
50+ /**
51+ * Calculate the surface area of a pyramid with a square base.
52+ *
53+ * @param sideLength side length of the square base
54+ * @param slantHeight slant height of the pyramid
55+ * @return surface area of the given pyramid
56+ */
57+ public static double surfaceAreaPyramid (final double sideLength , final double slantHeight ) {
58+ if (sideLength <= 0 ) {
59+ throw new IllegalArgumentException ("Must be a positive sideLength" );
60+ }
61+ if (slantHeight <= 0 ) {
62+ throw new IllegalArgumentException ("Must be a positive slantHeight" );
63+ }
64+ double baseArea = sideLength * sideLength ;
65+ double lateralSurfaceArea = 2 * sideLength * slantHeight ;
66+ return baseArea + lateralSurfaceArea ;
67+ }
5068
5169 /**
5270 * Calculate the area of a rectangle.
You can’t perform that action at this time.
0 commit comments