From 6c6d6fed24f475ed7e153f209650fd93ff42fd1d Mon Sep 17 00:00:00 2001 From: Marco Steinke <49523050+MarcoSteinke@users.noreply.github.com> Date: Thu, 30 Sep 2021 20:06:52 +0200 Subject: [PATCH] Add surfaceAreaCylinder (hacktoberfest) (#2337) --- Maths/Area.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Maths/Area.java b/Maths/Area.java index ea1db120b..6b5e45f27 100644 --- a/Maths/Area.java +++ b/Maths/Area.java @@ -28,6 +28,9 @@ public class Area { /* test circle */ assert Double.compare(surfaceAreaCircle(20), 1256.6370614359173) == 0; + + /* test cylinder */ + assert Double.compare(surfaceAreaCylinder(1,2), 18.84955592153876) == 0; } /** @@ -60,6 +63,16 @@ public class Area { private static double surfaceAreaRectangle(double length, double width) { return length * width; } + + /** + * Calculate surface of a cylinder + * + * @param radius radius of the floor + * @param height height of the cylinder. + */ + private static double surfaceAreaCylinder(double radius, double height) { + return 2 * (Math.PI * radius * radius + Math.PI * radius * height); + } /** * Calculate the area of a square