Skip to content

Commit 7c56a73

Browse files
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
1 parent 1e8abf1 commit 7c56a73

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

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

+12
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,16 @@ public static double volumePrism(double baseArea, double height) {
9090
public static double volumePyramid(double baseArea, double height) {
9191
return (baseArea * height) / 3;
9292
}
93+
94+
/**
95+
* Calculate the volume of a frustum of a cone.
96+
*
97+
* @param r1 radius of the top of the frustum
98+
* @param r2 radius of the bottom of the frustum
99+
* @param height height of the frustum
100+
* @return volume of the frustum
101+
*/
102+
public static double volumeFrustumOfCone(double r1, double r2, double height) {
103+
return (Math.PI * height / 3) * (r1 * r1 + r2 * r2 + r1 * r2);
104+
}
93105
}

src/test/java/com/thealgorithms/maths/VolumeTest.java

+3
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,8 @@ public void volume() {
3232

3333
/* test pyramid */
3434
assertTrue(Volume.volumePyramid(10, 3) == 10.0);
35+
36+
/* test frustum */
37+
assertTrue(Volume.volumeFrustumOfCone(3, 5, 7) == 359.188760060433);
3538
}
3639
}

0 commit comments

Comments
 (0)