Skip to content

Commit 3dc70da

Browse files
added surface area calculation for a pyramid
1 parent 410f087 commit 3dc70da

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

  • src/main/java/com/thealgorithms/maths

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static double surfaceAreaCube(final double sideLength) {
3535
return 6 * sideLength * sideLength;
3636
}
3737

38+
3839
/**
3940
* Calculate the surface area of a cuboid.
4041
*
@@ -69,24 +70,25 @@ public static double surfaceAreaSphere(final double radius) {
6970
return 4 * Math.PI * radius * radius;
7071
}
7172

72-
/**
73-
* Calculate the surface area of a pyramid with a square base.
74-
*
75-
* @param sideLength side length of the square base
76-
* @param slantHeight slant height of the pyramid
77-
* @return surface area of the given pyramid
78-
*/
79-
public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) {
80-
if (sideLength <= 0) {
81-
throw new IllegalArgumentException("");
82-
}
83-
if (slantHeight <= 0) {
84-
throw new IllegalArgumentException("slant height must be greater than 0");
85-
}
86-
double baseArea = sideLength * sideLength;
87-
double lateralSurfaceArea = 2 * sideLength * slantHeight;
88-
return baseArea + lateralSurfaceArea;
89-
}
73+
/**
74+
* Calculate the surfae area of a pyramid with a square base.
75+
*
76+
* @param sideLength
77+
* @param slantHeight
78+
* @return
79+
*/
80+
81+
public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) {
82+
if (sideLength <= 0) {
83+
throw new IllegalArgumentException("Must be a positive sideLength");
84+
}
85+
if (slantHeight <= 0) {
86+
throw new IllegalArgumentException("Must be a positive slantHeight");
87+
}
88+
double baseArea = sideLength * sideLength;
89+
double lateralSurfaceArea = 2 * sideLength * slantHeight;
90+
return baseArea + lateralSurfaceArea;
91+
}
9092

9193
/**
9294
* Calculate the area of a rectangle.

0 commit comments

Comments
 (0)