From 9e368100fef30116a9531bb71d21ef32fae13de5 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: Sun, 31 Oct 2021 17:12:49 +0530 Subject: [PATCH] Add surface area of Cone and Hemisphere (#2791) --- Maths/Area.java | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Maths/Area.java b/Maths/Area.java index 6b5e45f27..c721a3048 100644 --- a/Maths/Area.java +++ b/Maths/Area.java @@ -31,6 +31,15 @@ public class Area { /* test cylinder */ assert Double.compare(surfaceAreaCylinder(1,2), 18.84955592153876) == 0; + + /* test hemisphere */ + assert Double.compare(surfaceAreaHemisphere(5), 235.61944901923448) == 0; + assert Double.compare(surfaceAreaHemisphere(1), 9.42477796076938) == 0; + + /* test cone */ + assert Double.compare(surfaceAreaCone(6, 8), 301.59289474462014) == 0; + assert Double.compare(surfaceAreaCone(10, 24), 1130.9733552923256) == 0; + } /** @@ -127,4 +136,25 @@ public class Area { private static double surfaceAreaCircle(double radius) { return Math.PI * radius * radius; } + + /** + * Calculate the surface area of a hemisphere. + * + * @param radius radius of hemisphere + * @return surface area of given hemisphere + */ + private static double surfaceAreaHemisphere(double radius) { + return 3 * Math.PI * radius * radius; + } + + /** + * Calculate the surface area of a cone. + * + * @param radius radius of cone. + * @param height of cone. + * @return surface area of given cone. + */ + private static double surfaceAreaCone(double radius, double height) { + return Math.PI * radius * (radius + Math.pow((height * height + radius * radius), 0.5)); + } }