Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/main/java/com/thealgorithms/maths/Volume.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static double volumeCone(double radius, double height) {
/**
* Calculate the volume of a prism.
*
* @param baseArea area of the given prism's base
* @param baseArea area of the given prism's base
* @param height of given prism
* @return volume of given prism
*/
Expand All @@ -83,11 +83,23 @@ public static double volumePrism(double baseArea, double height) {
/**
* Calculate the volume of a pyramid.
*
* @param baseArea of the given pyramid's base
* @param baseArea of the given pyramid's base
* @param height of given pyramid
* @return volume of given pyramid
*/
public static double volumePyramid(double baseArea, double height) {
return (baseArea * height) / 3;
}

/**
* Calculate the volume of a pyramid.
*
* @param r1 radius of top of frustum
* @param r2 radius of bottom of frustum
* @param height of given frustum
* @return volume of given frustum
*/
public static double volumeFurstumOfCone(double r1, double r2, double height) {
return ((Math.PI * height) / 3) * (r1 * r1 + r2 * r2 + r1 * r2);
}
}
3 changes: 3 additions & 0 deletions src/test/java/com/thealgorithms/maths/VolumeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@ public void volume() {

/* test pyramid */
assertTrue(Volume.volumePyramid(10, 3) == 10.0);

/* test frustum */
assertTrue(Volume.volumeFurstumOfCone(3, 5, 7) == 359.188760060433);
}
}