Loading...
Loading...
An interior designer needs the area of circles, rectangles and triangles drawn on a floor plan.
Write a utility class Geometry with a private constructor (nobody needs a Geometry object) and three static methods: circleArea(double r), rectangleArea(double l, double w) and triangleArea(double b, double h). main calls them through the class name.
circle r, rectangle l w or triangle b h with whole numbers.shape area, with the area printed with two digits after the decimal point.Example
Input
3 circle 7 rectangle 4 5 triangle 10 3
Output
circle 153.94 rectangle 20.00 triangle 15.00
A triangle's area is half of base × height.
Try the problem first. Open one hint at a time.
A static method uses only its parameters, so it needs no object and no fields.
A private constructor stops new Geometry() from compiling outside the class.
Use Math.PI, and multiply by 0.5 (not 1 / 2) for the triangle.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor