Skip to content

Commit 5c7c6c4

Browse files
authored
Add volume of prism and pyramid (#2902)
1 parent a0a3922 commit 5c7c6c4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ public static void main(String[] args) {
2323

2424
/* test cone */
2525
assert Double.compare(volumeCone(5, 7), 916.297857297023) == 0;
26+
27+
/*test prism*/
28+
assert Double.compare(volumePrism(10, 2), 20.0) == 0;
29+
30+
/*test pyramid*/
31+
assert Double.compare(volumePyramid(10, 3), 10.0) == 0;
2632

2733
}
2834

@@ -89,4 +95,26 @@ private static double volumeHemisphere(double radius) {
8995
private static double volumeCone(double radius, double height) {
9096
return Math.PI * radius * radius * height / 3;
9197
}
98+
99+
/**
100+
* Calculate the volume of a prism.
101+
*
102+
* @param area of the base.
103+
* @param height of prism.
104+
* @return volume of given prism.
105+
*/
106+
private static double volumePrism(double basearea, double height) {
107+
return basearea * height;
108+
}
109+
110+
/**
111+
* Calculate the volume of a pyramid.
112+
*
113+
* @param area of the base.
114+
* @param height of pyramid.
115+
* @return volume of given pyramid.
116+
*/
117+
private static double volumePyramid(double basearea, double height) {
118+
return basearea * height / 3;
119+
}
92120
}

0 commit comments

Comments
 (0)