Skip to content

Commit 43da050

Browse files
authored
Added surface area of cone and hemisphere
1 parent 664bcf4 commit 43da050

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Maths/Area.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ public static void main(String[] args) {
1010
/* test sphere */
1111
assert Double.compare(surfaceAreaSphere(5), 314.1592653589793) == 0;
1212
assert Double.compare(surfaceAreaSphere(1), 12.566370614359172) == 0;
13+
14+
/* test hemisphere */
15+
assert Double.compare(surfaceAreaHemiphere(5), 235.61944901923448) == 0;
16+
assert Double.compare(surfaceAreaHemiphere(1), 9.42477796076938) == 0;
17+
18+
/* test cone */
19+
assert Double.compare(surfaceAreaCone(6, 8), 301.59289474462014) == 0;
20+
assert Double.compare(surfaceAreaCone(10, 24), 1130.9733552923256) == 0;
1321

1422
/* test rectangle */
1523
assert Double.compare(surfaceAreaRectangle(10, 20), 200.0) == 0;
@@ -53,6 +61,27 @@ private static double surfaceAreaSphere(double radius) {
5361
return 4 * Math.PI * radius * radius;
5462
}
5563

64+
/**
65+
* Calculate the surface area of a hemisphere.
66+
*
67+
* @param radius radius of hemisphere
68+
* @return surface area of given hemisphere
69+
*/
70+
private static double surfaceAreaHemisphere(double radius) {
71+
return 3 * Math.PI * radius * radius;
72+
}
73+
74+
/**
75+
* Calculate the surface area of a cone.
76+
*
77+
* @param radius radius of cone.
78+
* @param height of cone.
79+
* @return surface area of given cone.
80+
*/
81+
private static double surfaceAreaCone(double radius, double height) {
82+
return Math.PI * radius * (radius + Math.pow((height * height + radius * radius), 0.5));
83+
}
84+
5685
/**
5786
* Calculate the area of a rectangle
5887
*

0 commit comments

Comments
 (0)