Skip to content

Commit 5a1c51b

Browse files
authored
Added surface area of a cuboid
Added surface area of a cuboid according to the formula: S = 2 * (ab + ac + bc)
1 parent ba286b2 commit 5a1c51b

File tree

1 file changed

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

1 file changed

+21
-0
lines changed

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

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

38+
/**
39+
* Calculate the surface area of a cuboid.
40+
*
41+
* @param length length of the cuboid
42+
* @param width width of the cuboid
43+
* @param height height of the cuboid
44+
* @return surface area of given cuboid
45+
*/
46+
public static double surfaceAreaCuboid(final double length, double width, double height) {
47+
if (length <= 0) {
48+
throw new IllegalArgumentException("Length must be greater than 0");
49+
}
50+
if (width <= 0) {
51+
throw new IllegalArgumentException("Width must be greater than 0");
52+
}
53+
if (height <= 0) {
54+
throw new IllegalArgumentException("Height must be greater than 0");
55+
}
56+
return 2 * (length * width + length * height + width * height);
57+
}
58+
3859
/**
3960
* Calculate the surface area of a sphere.
4061
*

0 commit comments

Comments
 (0)