diff --git a/src/main/java/com/thealgorithms/maths/Volume.java b/src/main/java/com/thealgorithms/maths/Volume.java index 4b73f849bb81..2296e8c21744 100644 --- a/src/main/java/com/thealgorithms/maths/Volume.java +++ b/src/main/java/com/thealgorithms/maths/Volume.java @@ -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 */ @@ -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); + } } diff --git a/src/test/java/com/thealgorithms/maths/VolumeTest.java b/src/test/java/com/thealgorithms/maths/VolumeTest.java index 1bdb3ae80040..9f3c2904fad2 100644 --- a/src/test/java/com/thealgorithms/maths/VolumeTest.java +++ b/src/test/java/com/thealgorithms/maths/VolumeTest.java @@ -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); } }