
Prompt the user to choose an item/product using the number (1,2,3) that corresponds to the item, or to enter 0 to quit the application. After the user makes the first selection, if the choice is 0, display a bill of RM0. Otherwise, display the menu again.

import java.util.*;
class ChoiceExample
{
public static void main(String[] args)
{
double price=0;
Scanner input=new Scanner(System.in);
boolean exit=false;
do{
System.out.println("0 Exit");
System.out.println("1 Toys");
System.out.println("2 Books");
System.out.println("3 Bags");
System.out.print("Enter your choice: ");
int choice=input.nextInt();
switch(choice){
case 0:
exit=true;
System.exit(0);
break;
case 1:
price=200;
System.out.println("Price is: "+price);
break;
case 2:
price=500;
System.out.println("Price is: "+price);
break;
case 3:
price=250;
System.out.println("Price is: "+price);
break;
}
}
while(!exit);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.