From 5c7c6c470260c3cb6964fae96d4deb17ee82dba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C9=AA=C9=B4=E1=B4=80=CA=8F=E1=B4=80=E1=B4=8B=20P?= =?UTF-8?q?=E1=B4=80=C9=B4=E1=B4=85=E1=B4=87=CA=8F?= <87496159+Harpia-Vieillot@users.noreply.github.com> Date: Mon, 10 Jan 2022 15:06:37 +0530 Subject: [PATCH] Add volume of prism and pyramid (#2902) --- .../java/com/thealgorithms/maths/Volume.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/java/com/thealgorithms/maths/Volume.java b/src/main/java/com/thealgorithms/maths/Volume.java index 6a08a6c7..c1c20a6c 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; + } }