Modify before asshignment so that we can check input errors

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;

}

}

  

Solution

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();
}
}
}

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 yo
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 yo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site