File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
src/main/java/com/thealgorithms/maths Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,32 @@ public static double surfaceAreaCube(final double sideLength) {
3535 return 6 * sideLength * sideLength ;
3636 }
3737
38+
39+ /**
40+ * Calculate the surface area of a pyramid with a square base.
41+ *
42+ * @param sideLength side length of the square base
43+ * @param slantHeight slant height of the pyramid
44+ * @return surface area of the given pyramid
45+ */
46+ public static double surfaceAreaPyramid (final double sideLength , final double slantHeight ) {
47+ if (sideLength <= 0 ) {
48+ throw new IllegalArgumentException ("Must be a positive sideLength" );
49+ }
50+ if (slantHeight <= 0 ) {
51+ throw new IllegalArgumentException ("Must be a positive slantHeight" );
52+ }
53+ double baseArea = sideLength * sideLength ;
54+ double lateralSurfaceArea = 2 * sideLength * slantHeight ;
55+ return baseArea + lateralSurfaceArea ;
56+ }
57+
58+
59+
60+
61+
62+
63+
3864 /**
3965 * Calculate the surface area of a sphere.
4066 *
@@ -192,4 +218,8 @@ public static double surfaceAreaCone(final double radius, final double height) {
192218 }
193219 return Math .PI * radius * (radius + Math .pow (height * height + radius * radius , 0.5 ));
194220 }
221+
222+
223+
224+
195225}
You can’t perform that action at this time.
0 commit comments