Skip to content

Commit 3fd6669

Browse files
authored
Update Area.java
1 parent fd30fdf commit 3fd6669

File tree

1 file changed

+19
-19
lines changed
  • src/main/java/com/thealgorithms/maths

1 file changed

+19
-19
lines changed

src/main/java/com/thealgorithms/maths/Area.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,6 @@
66
public final class Area {
77
private Area() {
88
}
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-
289
/**
2910
* String of IllegalArgumentException for radius
3011
*/
@@ -210,4 +191,23 @@ public static double surfaceAreaCone(final double radius, final double height) {
210191
}
211192
return Math.PI * radius * (radius + Math.pow(height * height + radius * radius, 0.5));
212193
}
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+
213213
}

0 commit comments

Comments
 (0)