Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Maths/Area.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ public static void main(String[] args) {

/* 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;

}

/**
Expand Down Expand Up @@ -127,4 +136,25 @@ private static double surfaceAreaTrapezium(double base1, double base2, double he
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));
}
}