Question: IN JAVA: Add a static method which computes the area of several common shapes: triangle, rectangle and parallelogram. The class should have a single static

IN JAVA:

Add a static method which computes the area of several common shapes: triangle, rectangle and parallelogram. The class should have a single static method called printArea that takes in three parameters: an enum for the shape type, a double for the base and a double for the height.

Your program will first ask the user to type in a shape (square, parallelogram, triangle) , base and height via the console. Then, use an IF-ELSE statement to call the printArea() method with the appropriate parameters.

As a reminder, the equations for area for the above shapes is: areasquare = bh

areaparallelogram = bh areatriangle = bh*(1/2)

Your printArea method will be static, so you should be able to call it within your main() method. For example, you may call your method using the following code: printArea(RECTANGLE, 2.5, 3.2);, which may yield the following output: The rectangle with base of 2.5 and height of 3.2 has an area of 8.0.

Sample output with bold being user input:

Please enter a shape (e.g. Square, Parallelogram, Triangle): Parallelogram

Please enter the base value: 2.5 Please enter the height value: 4.6 The parallelogram with base of 2.5 and height of 4.6 has an area of 11.5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!