diff --git a/src/main/java/com/thealgorithms/maths/Volume.java b/src/main/java/com/thealgorithms/maths/Volume.java index 6a08a6c78..c1c20a6c3 100644 --- a/src/main/java/com/thealgorithms/maths/Volume.java +++ b/src/main/java/com/thealgorithms/maths/Volume.java @@ -23,6 +23,12 @@ public class Volume { /* test cone */ assert Double.compare(volumeCone(5, 7), 916.297857297023) == 0; + + /*test prism*/ + assert Double.compare(volumePrism(10, 2), 20.0) == 0; + + /*test pyramid*/ + assert Double.compare(volumePyramid(10, 3), 10.0) == 0; } @@ -89,4 +95,26 @@ public class Volume { private static double volumeCone(double radius, double height) { return Math.PI * radius * radius * height / 3; } + + /** + * Calculate the volume of a prism. + * + * @param area of the base. + * @param height of prism. + * @return volume of given prism. + */ + private static double volumePrism(double basearea, double height) { + return basearea * height; + } + + /** + * Calculate the volume of a pyramid. + * + * @param area of the base. + * @param height of pyramid. + * @return volume of given pyramid. + */ + private static double volumePyramid(double basearea, double height) { + return basearea * height / 3; + } }