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

Modify before asshignment so that we can check input errors, etc.. Please refer

ID: 3933790 • Letter: M

Question

Modify before asshignment so that we can check input errors, etc.. Please refer to the following Java code.

You should add switch, run your programing untill you choose figure==0 (using while loop), cheak input error.

import java.util.*;

public class AreaTestt {

  

public static void main (String[] args)

{

  

int choice1 = menu(1);

  

int choice2 = menu(2)

}

  

  

  

  

  

  

// get user choice

public static int menu(int n)

{

int choice = 0;

Scanner scanner = new Scanner(System.in);

if(n == 1)

{

System.out.print("Information for figure 1: Type 1) rectangle 2) triangle 3) circle: ");

choice = scanner.nextInt();

}

  

else if(n == 2)

{

System.out.print("Information for figure 2: Type 1) rectangle 2) triangle 3) circle: ");

choice = scanner.nextInt();

}

  

return choice;

}

}

  

Explanation / Answer

import java.util.*;

public class AreaTestt {

public static void main (String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.print("Information for figure 1: Type 1) rectangle 2) triangle 3) circle: 4) Exit ");
int choice = scanner.nextInt();
while(choice!=4){
switch (choice) {
case 1:
System.out.println("It is a Rectangle");
break;
case 2:
System.out.println("It is a Triangle");
break;
case 3:
System.out.println("It is a Circle");
break;

default:
System.out.println("Invalid Choice");
break;
}
System.out.println("Enter Your Choice ");
choice = scanner.nextInt();
}
}
}

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