@@ -31,6 +31,15 @@ public static void main(String[] args) {
31
31
32
32
/* test cylinder */
33
33
assert Double .compare (surfaceAreaCylinder (1 ,2 ), 18.84955592153876 ) == 0 ;
34
+
35
+ /* test hemisphere */
36
+ assert Double .compare (surfaceAreaHemisphere (5 ), 235.61944901923448 ) == 0 ;
37
+ assert Double .compare (surfaceAreaHemisphere (1 ), 9.42477796076938 ) == 0 ;
38
+
39
+ /* test cone */
40
+ assert Double .compare (surfaceAreaCone (6 , 8 ), 301.59289474462014 ) == 0 ;
41
+ assert Double .compare (surfaceAreaCone (10 , 24 ), 1130.9733552923256 ) == 0 ;
42
+
34
43
}
35
44
36
45
/**
@@ -127,4 +136,25 @@ private static double surfaceAreaTrapezium(double base1, double base2, double he
127
136
private static double surfaceAreaCircle (double radius ) {
128
137
return Math .PI * radius * radius ;
129
138
}
139
+
140
+ /**
141
+ * Calculate the surface area of a hemisphere.
142
+ *
143
+ * @param radius radius of hemisphere
144
+ * @return surface area of given hemisphere
145
+ */
146
+ private static double surfaceAreaHemisphere (double radius ) {
147
+ return 3 * Math .PI * radius * radius ;
148
+ }
149
+
150
+ /**
151
+ * Calculate the surface area of a cone.
152
+ *
153
+ * @param radius radius of cone.
154
+ * @param height of cone.
155
+ * @return surface area of given cone.
156
+ */
157
+ private static double surfaceAreaCone (double radius , double height ) {
158
+ return Math .PI * radius * (radius + Math .pow ((height * height + radius * radius ), 0.5 ));
159
+ }
130
160
}
0 commit comments