Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting And Auditing Research And Databases Practitioner's Desk Reference

Authors: Thomas R. Weirich, Natalie Tatiana Churyk, Thomas C. Pearson

1st Edition

1118334426, 978-1118334423

More Books

Students also viewed these Databases questions