Modify your solution for PLP04 to allow the user to choose t
Modify your solution for PLP04 to allow the user to choose the shape to compute and report. The change should make the \"look and feel\" of the program cleaner and the user experience less cumbersome. There are several selection structure implementations (if-else, switch) that can be used in the solution. The user should be provided with a \"menu of choices\" that will allow them to identify the shape they wish to work with. A typical session might look like this:
 
 
 Choose the shape
 1. Square
 2. Rectangle
 3. Circle
 4. Triangle
 5. Quit
 Enter your choice: 1
 
 Enter the side (as a decimal): 10.5
 The area is 110.25
 The perimeter is: 42.0
 
 Thank you
Procedure:
Locate your PLP04.java source file in your files and edit with Eclipse.
Add the comment // modified by: ... and supply your name and the current date.
Save the program with the file name xxPLP05.java where xx are your initials. Be sure to change the class name to this as well (to avoid the run-time error \"class not found\" message).
Modify the program as indicated in the Problem Statement above.
Compile the program and correct any syntax errors detected by the compiler.
When the syntax errors have been corrected, test the program in Eclipe. Before testing, on paper, create test data and perform the computations manually. These will serve as your control for testing.
Compare the results produced by your program with your hand derived results.
Using the commenting facility, put your test data at the end of the program file.
Notes:
Modify your copy of PLP04.java for this assignment. The original should be stored on your flashdrive.
Use the same \"prompt and respond\" dialog from your version of PLP04.java to collect the data and report the results for each of the other three shapes. A refresher:
Should the user choose the rectangle (2):
 
 Enter the first side (as a decimal): 10.5
 Enter the second side (as a decimal): 15.5
 The area is 162.75
 The perimeter is: 52.0
Should the user choose the circle (3)
 
 Enter the radius (decimal): 30.2
 The area is:2,865.2557
 The circumference is: 189.752
Should the user choose the triangle:
 
 Enter the height of the triangle (decimal): 3.0
 Enter the base of the triangle (decimal): 4.0
 The area is: 6.0
 The perimeter is 12.0
When deciding on the data type to use for your sides (rectangle), radius (circle), base and height (triangle) consider how you will use them and the numeric types that will be used in the computations.
Declare PI as a named constant and assign it the value of 3.14159 at the time of declaration.
Notice that the example above strongly suggests that your program will require a series of interactions with the user in order to gather data for each set of shape calculations.
Assume you will be working with a right triangle (a triangle of 90 degrees).
Some calculations you may find useful:
for the perimeter of a rectangle:
 perimeter = 2 * (side1 + side2)
for the circumference of a circle:
 circumference = 2 * PI * radius
for the perimeter of a triangle:
 perimeter = base + height + hypotenuse
to find the hypotenuse of the right triangle:
 hyptenuse2 = base2 + height2
Here is the original, from what we should be working with.
import java.util.Scanner;
 public class PLP04 {
   public static void main (String[] args)
    {
    double side1 = 0.0;
    double side2 = 0.0;
    double radius = 0.0;
    double base = 0.0;
    double height = 0.0;
    double hypotenuse = 0.0;
    final double PI = 3.14159;
   System.out.print(\"Enter the first side \");
    Scanner inData; // A class that reads input
    inData = new Scanner(System.in);
    System.out.print(\"\ Enter the length of a side \");
    side1 = inData.nextDouble();
    System.out.print(\"\ Enter the length of second side \");
        side2 = inData.nextDouble();
    System.out.println(\"\ The area is \" + side1 * side2 + \"\ \");
    System.out.println(\"The perimeter is \" + 2 * (side1 + side2));
   
    System.out.print(\"\ Enter the radius (decimal):\");
    radius = inData.nextDouble();
    System.out.println(\"The area is:\" + radius * radius * PI);
    System.out.println(\"The circumference is:\" + 2 * PI * radius);
   
    System.out.print(\"\ Enter the height of the triangle (decimal):\");
    height= inData.nextDouble();
    System.out.print(\"Enter the base of the triangle (decimal):\");
    base = inData.nextDouble();
    hypotenuse = Math.sqrt((base * base) + (height * height));
    System.out.println(\"\ The area is: \" + (base * height)/2 + \"\ \");
    System.out.println(\"\ The perimeter is \" + (base + height + hypotenuse) + \"\ \");
// Enter the first side (as a decimal): 20.5
 // Enter the second side (as a decimal): 15.0
 // The area is = 20.5 * 15.0 = 307.5
 // The perimeter is = 2(20.5 + 15.0) = 71.0
 //
 // Enter the radius (decimal): 30.2
 // The area is = 30.2 * 3.14 * 3.14 = 2,865.2557
 // The circumference is = 2 * 30.2 * 3.14 = 189.752
 //
 // Enter the height of the triangle (decimal): 3.0
 // Enter the base of the triangle (decimal): 4.0
 // The area is = (3 * 4)/2 = 6.0
 //
 }
 }
   
         
Solution
PLP04.java
import java.util.Scanner;
public class PLP04 {
    //Declaring constant
    public static final double PI = 3.14159;
   public static void main(String[] args) {
       
        //Declaring variable
        int choice;
       
        //Scanner class Obejct is used to read the inputs entered by the user
        Scanner sc = new Scanner(System.in);
       //This loop continues to execute until user enters choice \'5\'
        do {
            //Displaying the menu
            System.out.println(\"\ \ Choose the shape\");
            System.out.println(\"1. Square\");
            System.out.println(\"2. Rectangle\");
            System.out.println(\"3. Circle\");
            System.out.println(\"4. Triangle\");
            System.out.println(\"5. Quit\");
            System.out.print(\"Enter your choice:\");
            choice = sc.nextInt();
           //Based on the User selection the corresponding case will be executed
            switch (choice) {
           
            //This case will calculate the area and perimeter of the square
            case 1: {
                //Declaring variables
                double side, area, perimeter;
               
                //Getting the side of the square entered by the user
                System.out.print(\"Enter the side (as a decimal):\");
                side = sc.nextDouble();
               
                //calculating the area of the square
                area = side * side;
               
                //calculating the perimeter of the square
                perimeter = 4 * side;
               
                //Displaying the area of the square
                System.out.println(\"The area is \" + area);
               
                //Displaying the perimeter of the square;
                System.out.println(\"The perimeter is \" + perimeter);
                break;
            }
            case 2: {
               
                //Declaring variables
                double firstside, secondside, area, perimeter;
               
                //Getting the first side of the rectangle
                System.out.print(\"Enter the first side (as a decimal):\");
                firstside = sc.nextDouble();
               
                //Getting the second side of the rectangle
                System.out.print(\"Enter the second side (as a decimal):\");
                secondside = sc.nextDouble();
               
                //Calculating the area of the rectangle
                area = firstside * secondside;
               
                //Calculating the perimeter of the rectangle
                perimeter = 2 * firstside + 2 * secondside;
               
                //Displaying the area of the rectangle
                System.out.println(\"The area is \" + area);
               
                //Displaying the perimeter of the rectangle
                System.out.println(\"The perimeter is: \" + perimeter);
                break;
           }
            case 3: {
                //Declaring variables
                double radius, area, circumference;
               
                //Getting the radius of the circle
                System.out.print(\"Enter the radius (decimal):\");
                radius = sc.nextDouble();
               
                //calculating the area of the circle
                area = PI * radius * radius;
               
                //calculating the circumference of the circle
                circumference = 2 * PI * radius;
               
                //displaying the area of the circle
                System.out.printf(\"The area is %.2f \", area);
               
                //displaying the circumference of the circle
                System.out.printf(\"\ The circumference is %.2f \", circumference);
                break;
            }
            case 4: {
               
                //Declaring variables
                double height, base, area, perimeter, hypotenuse;
               
                //Getting the height of the triangle
                System.out.print(\"Enter the height of the triangle (decimal):\");
                height = sc.nextDouble();
               
                //Getting the base of the triangle
                System.out.print(\"Enter the base of the triangle (decimal):\");
                base = sc.nextDouble();
               
                //calculating the area of the triangle
                area = 0.5 * base * height;
               
                //calculating the hypotenuse of the triangle
                hypotenuse = Math.sqrt(Math.pow(base, 2) + Math.pow(height, 2));
               
                //Calculating the perimeter of the triangle
                perimeter = base + height + hypotenuse;
               
                //Displaying the area of the triangle
                System.out.printf(\"The area is %.2f\", area);
               
                //Displaying the perimeter of the triangle
                System.out.printf(\"\ The perimeter is %.2f\", perimeter);
                break;
           }
            case 5: {
                break;
           }
            }
} while (choice != 5);
}
}
______________________________________
output:
Choose the shape
 1. Square
 2. Rectangle
 3. Circle
 4. Triangle
 5. Quit
 Enter your choice:1
 Enter the side (as a decimal):10.5
 The area is 110.25
 The perimeter is 42.0
 Choose the shape
 1. Square
 2. Rectangle
 3. Circle
 4. Triangle
 5. Quit
 Enter your choice:2
 Enter the first side (as a decimal):10.5
 Enter the second side (as a decimal):15.5
 The area is 162.75
 The perimeter is: 52.0
 Choose the shape
 1. Square
 2. Rectangle
 3. Circle
 4. Triangle
 5. Quit
 Enter your choice:3
 Enter the radius (decimal):30.2
 The area is 2865.26
 The circumference is 189.75
Choose the shape
 1. Square
 2. Rectangle
 3. Circle
 4. Triangle
 5. Quit
 Enter your choice:4
 Enter the height of the triangle (decimal):3.0
 Enter the base of the triangle (decimal):4.0
 The area is 6.00
 The perimeter is 12.00
Choose the shape
 1. Square
 2. Rectangle
 3. Circle
 4. Triangle
 5. Quit
 Enter your choice:5
________________Thank You






