Skip to content

Commit e0f4755

Browse files
committed
Issue #5479 : added volume function in main folder and assert function in test folder under math/Volume
1 parent 1e8abf1 commit e0f4755

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,20 @@ 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+
/**
96+
* Calculate the volume of a pyramid.
97+
*
98+
* @param r1 radius of top of frustum
99+
* @param r2 radius of bottom of frustum
100+
* @param height of given frustum
101+
* @return volume of given frustum
102+
*/
103+
public static double volumeFurstumOfCone(double r1, double r2, double height) {
104+
return ((Math.PI * height) / 3) * (r1 * r1 + r2 * r2 + r1 * r2);
105+
}
106+
107+
108+
93109
}

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

Lines changed: 3 additions & 0 deletions
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.volumeFurstumOfCone(3, 5, 7) == 359.188760060433);
3538
}
3639
}

0 commit comments

Comments
 (0)