File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
src/main/java/com/thealgorithms/maths Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,26 @@ public static double surfaceAreaCube(final double sideLength) {
3535 return 6 * sideLength * sideLength ;
3636 }
3737
38+ /**
39+ * Calculate the surface area of a pyramid with a square base.
40+ *
41+ * @param sideLength side length of the square base
42+ * @param slantHeight slant height of the pyramid
43+ * @return surface area of the given pyramid
44+ */
45+ public static double surfaceAreaPyramid (final double sideLength , final double slantHeight ) {
46+ if (sideLength <= 0 ) {
47+ throw new IllegalArgumentException ("Must be a positive sideLength" );
48+ }
49+ if (slantHeight <= 0 ) {
50+ throw new IllegalArgumentException ("Must be a positive slantHeight" );
51+ }
52+ double baseArea = sideLength * sideLength ;
53+ double lateralSurfaceArea = 2 * sideLength * slantHeight ;
54+ return baseArea + lateralSurfaceArea ;
55+ }
56+
57+
3858 /**
3959 * Calculate the surface area of a sphere.
4060 *
You can’t perform that action at this time.
0 commit comments