|
6 | 6 | public final class Area { |
7 | 7 | private Area() { |
8 | 8 | } |
9 | | -/** |
10 | | - * Calculate the surface area of a pyramid with a square base. |
11 | | - * |
12 | | - * @param sideLength side length of the square base |
13 | | - * @param slantHeight slant height of the pyramid |
14 | | - * @return surface area of the given pyramid |
15 | | - */ |
16 | | -public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) { |
17 | | - if (sideLength <= 0) { |
18 | | - throw new IllegalArgumentException("Must be a positive sideLength"); |
19 | | - } |
20 | | - if (slantHeight <= 0) { |
21 | | - throw new IllegalArgumentException("Must be a positive slantHeight"); |
22 | | - } |
23 | | - double baseArea = sideLength * sideLength; |
24 | | - double lateralSurfaceArea = 2 * sideLength * slantHeight; |
25 | | - return baseArea + lateralSurfaceArea; |
26 | | -} |
27 | | - |
28 | 9 | /** |
29 | 10 | * String of IllegalArgumentException for radius |
30 | 11 | */ |
@@ -210,4 +191,23 @@ public static double surfaceAreaCone(final double radius, final double height) { |
210 | 191 | } |
211 | 192 | return Math.PI * radius * (radius + Math.pow(height * height + radius * radius, 0.5)); |
212 | 193 | } |
| 194 | + /** |
| 195 | + * Calculate the surface area of a pyramid with a square base. |
| 196 | + * |
| 197 | + * @param sideLength side length of the square base |
| 198 | + * @param slantHeight slant height of the pyramid |
| 199 | + * @return surface area of the given pyramid |
| 200 | + */ |
| 201 | +public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) { |
| 202 | + if (sideLength <= 0) { |
| 203 | + throw new IllegalArgumentException("Must be a positive sideLength"); |
| 204 | + } |
| 205 | + if (slantHeight <= 0) { |
| 206 | + throw new IllegalArgumentException("Must be a positive slantHeight"); |
| 207 | + } |
| 208 | + double baseArea = sideLength * sideLength; |
| 209 | + double lateralSurfaceArea = 2 * sideLength * slantHeight; |
| 210 | + return baseArea + lateralSurfaceArea; |
| 211 | +} |
| 212 | + |
213 | 213 | } |
0 commit comments