Can someone please help me with this, I\'m lost. This is for Intro to Java Progr
ID: 3844672 • Letter: C
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 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 user’s shape choice and output the formula as well as the results
In addition, implement a Switch/Case block to act on the user’s 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
Explanation / Answer
import java.util.*;
import static java.lang.Math.*;
class Areas
{
public static void main (String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println(" Please Select an area to determine from the following menu choices.");
System.out.println(" 1. Determine the area of a Square");
System.out.println(" 2. Determine the area of a Circle");
System.out.println(" 3. Determine the area of a Ellipse");
System.out.println(" 4. Determine the area of a Pentagon");
System.out.println(" 5. Exit.");
int option = scan.nextInt();
if(option == 1)
{
System.out.println(" Enter the side of square:");
double side = scan.nextDouble();
System.out.println(" The formula for the area of a square side * side ") ;
System.out.println(" The area of a square with a side of "+side +" is:"+ side*side);
}
else if(option == 2)
{
System.out.println(" Enter the radius of the circle:");
double radius = scan.nextDouble();
System.out.println(" The formula for the area of a circle PI * r^2 ") ;
System.out.println(" The area of a circle with a radius of "+ radius +" is: "+ PI*radius*radius);
}
else if(option == 3)
{
System.out.println(" Enter the radius1 and radius 2 of the ellipse:");
double radius1 = scan.nextDouble();
double radius2 = scan.nextDouble();
System.out.println(" The formula for the area of an ellipse is PI * Radius 1 * Radius 2") ;
System.out.println(" The area of an ellipse with a radius of 2 is: "+ PI * radius1 * radius2);
}
else if(option == 4)
{
System.out.println(" Enter the side of pentagon:");
double side = scan.nextDouble();
System.out.println(" The formula for the area of a Pentagon is 0.25 *(sqrt(5*(5+2(sqrt(5))))*side*side ") ;
System.out.println(" The area of pentagon with a side of "+side +" is:"+ 0.25*(sqrt(5*(5+2*(sqrt(5)))))*side*side);
}
else if(option == 5)
System.exit(0);
else
System.exit(1);
/* switch(option)
{
case 1: System.out.println(" Enter the side of square:");
double side = scan.nextDouble();
System.out.println(" The formula for the area of a square side * side ") ;
System.out.println(" The area of a square with a side of "+side +" is:"+ side*side);
break;
case 2: System.out.println(" Enter the radius of the circle:");
double radius = scan.nextDouble();
System.out.println(" The formula for the area of a circle PI * r^2 ") ;
System.out.println(" The area of a circle with a radius of "+ radius +" is: "+ PI*radius*radius);
break;
case 3: System.out.println(" Enter the radius1 and radius 2 of the ellipse:");
double radius1 = scan.nextDouble();
double radius2 = scan.nextDouble();
System.out.println(" The formula for the area of an ellipse is PI * Radius 1 * Radius 2") ;
System.out.println(" The area of an ellipse with a radius of 2 is: "+ PI * radius1 * radius2);
break;
case 4: System.out.println(" Enter the side of pentagon:");
side = scan.nextDouble();
System.out.println(" The formula for the area of a Pentagon is 0.25 *(sqrt(5*(5+2(sqrt(5))))*side*side ") ;
System.out.println(" The area of pentagon with a side of "+side +" is:"+ 0.25*(sqrt(5*(5+2*(sqrt(5)))))*side*side);
break;
case 5: System.exit(0);
break;
default : System.exit(1);
break;
}*/
}
}
output:
Please Select an area to determine from the following menu choices.
1. Determine the area of a Square
2. Determine the area of a Circle
3. Determine the area of a Ellipse
4. Determine the area of a Pentagon
5. Exit.
4
Enter the side of pentagon: 8
The formula for the area of a Pentagon is 0.25 *(sqrt(5*(5+2(sqrt(5))))*side*side
The area of pentagon with a side of 8.0 is:110.11055363769388