Add Volume "Algorithm Frustum Of Cone" Then Test It. (#5479)

* Add Function volumeFrustum To Calculate Frustum Of Cone Then Test It.

* Add Function volumeFrustumOfCone To Calculate Frustum Of Cone Then Test It.

* Update VolumeTest.java

* Update Volume.java
This commit is contained in:
Ahmed Elazab
2024-09-30 20:54:24 +03:00
committed by GitHub
parent 1e8abf1ddf
commit 7c56a734e9
2 changed files with 15 additions and 0 deletions

View File

@ -90,4 +90,16 @@ public final class Volume {
public static double volumePyramid(double baseArea, double height) {
return (baseArea * height) / 3;
}
/**
* Calculate the volume of a frustum of a cone.
*
* @param r1 radius of the top of the frustum
* @param r2 radius of the bottom of the frustum
* @param height height of the frustum
* @return volume of the frustum
*/
public static double volumeFrustumOfCone(double r1, double r2, double height) {
return (Math.PI * height / 3) * (r1 * r1 + r2 * r2 + r1 * r2);
}
}

View File

@ -32,5 +32,8 @@ public class VolumeTest {
/* test pyramid */
assertTrue(Volume.volumePyramid(10, 3) == 10.0);
/* test frustum */
assertTrue(Volume.volumeFrustumOfCone(3, 5, 7) == 359.188760060433);
}
}