File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
src/main/java/com/thealgorithms/maths Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,12 @@ public static void main(String[] args) {
23
23
24
24
/* test cone */
25
25
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 ;
26
32
27
33
}
28
34
@@ -89,4 +95,26 @@ private static double volumeHemisphere(double radius) {
89
95
private static double volumeCone (double radius , double height ) {
90
96
return Math .PI * radius * radius * height / 3 ;
91
97
}
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
+ }
92
120
}
You can’t perform that action at this time.
0 commit comments