Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need to code in Java Modify your code to allow the user to choose the shape to c

ID: 3776790 • Letter: N

Question

Need to code in Java

Modify your code 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

Explanation / Answer

import java.util.Scanner;

public class HelloWorld {


     public static void main(String []args) {

         Scanner in = new Scanner(System.in);
         int input,input1;
         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.println("Enter your choice ");
         int choice = in.nextInt();
   
switch(choice) {
         case 1 :
           
            System.out.println("Enter the side (as a decimal): ");
            input = in.nextInt();
            System.out.println("The area is " + (input*input));
            System.out.println("The perimeter is " + (4*input));
            break;
        
         case 2 :
           
           
            System.out.println("Enter the length: ");
            input = in.nextInt();
           
            System.out.println("Enter the width: ");
            input1 = in.nextInt();
        
            System.out.println("The area is " + (input*input1));
            System.out.println("The perimeter is " + 2*(input + input1));
            break;

         case 3 :
           
            System.out.println("Enter the radius: ");
            input = in.nextInt();
            System.out.println("The area is " + (3.14*input*input));
            System.out.println("The circumference is " + (2*3.14*input));
            break;
        

         case 4 :
             System.out.println("Enter the base: ");
            input = in.nextInt();
           
            System.out.println("Enter the Height: ");
            input1 = in.nextInt();
        
            System.out.println("The area is " + (input*input1)/2);
            break;

          case 5 :
              System.out.println("Exist from the program");
            break;

         default :
            System.out.println("Invalid input ");
      }
    

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote