Question
Can someone please help me with this, I'm lost. This is for Intro to Java Programing course I'm taking. Set up the below program in
Can someone please help me with this, I'm lost. This is for Intro to Java Programing course I'm taking.
Set up the below program in Netbeans.
Write a program that will determine the area of a geometric shape. The program should ask the user to select a shape from a menu. The menu should have the following selections:
Square
Circle
Ellipse
Pentagon
Exit
for the areas.
Area.of a square a = side A = a2
Area of a Circle r = radius A = r2
Area of an Ellipse a = radius 1 b = radius 2 A = a b
Area of a Pentagon a = side A = 1/4 5(5+55) a2
Requirements
Use a menu for shape choices
Each shape will require an input (or two)
Implement if/else if statements to act on the users shape choice and output the formula as well as the results
In addition, implement a Switch/Case block to act on the users shape choice and output the formula as well as the results
Comment-out either the if/ else if blocks or the switch/case blocks so only one set can run per run session. Both blocks of code should be operational. The Instructor will comment/uncomment both to make sure each one is coded correctly. To comment out several lines of code at once, highlight the block of code, then select Source -> Toggle Comment from the NetBeans
The formula should be printed before the results are printed
Use the Math Class where appropriate (power, square root, PI, etc.)
Hints
Importing the Math class will save room when writing the formulas: import static java.lang.Math.*;
To exit a program cleanly, use the following code: System.exit(0);
To exit a program due to an error, use the following code: System.exit(1);
Use caution when building your formulas (see sample outputs below)
A default case (in Switch/Case block) can be used for erroneous menu entries
Expected Output
Below is a sample of the output for two runs of the program. User input is in red.
Run 1:
Please Select an area to determine from the following menu choices.
1. Determine the are of a Square
2. Determine the are of a Circle
3. Determine the are of a Ellipse
4. Determine the area of a Pentagon
5. Exit.
Enter the radius of the circle: 6 The formula for the area of a cricle PI * r^2
The area of a circle with a radius of 6 is: 113.09733552923255
Run 2:
Please select an area to determine from the following menu choices
1. Determine the are of a Square
2. Determine the are of a Circle
3. Determine the are of a Ellipse
4. Determine the area of a Pentagon
5. Exit.
Run 3:
Enter radius 1 of an ellipse: 7
Enter radius 2 of an ellipse: 2
The formula for the area of an ellipse is PI * Radius 1 * Radius 2
The area of an ellipse with a radius of 2 is: 43.982297150257104.
Additional sample results:
The area of a circle with a radius of 3 is: 28.274333882308138
The area of a pentagon with a side equal to 8 is: 110.11055363769388
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started