Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


Iswaran
jawa
1 Answer(s)      2 years and 7 months ago
Posted in : Java Beginners


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.


Advertisement
View Answers

September 2, 2011 at 4:39 PM


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


Related Tutorials/Questions & Answers:
Convert to java - Java Beginners
hari : Jawa (hari pasar) sBulanE = namaBulanE[iBulanM]; //string nama... - Jawa //iTanggalM : int tanggal Masehi (Inggris/Indonesia) //iTanggalH : int tanggal Hijriah (Arab/Indonesia/Jawa) zTanggalM = iTanggalM<10
Advertisements
Difference between Java 6 and Java 7
Needless to say, today Java has become the most widely object oriented programming languages and it has been playing crucial role by using this from software development to web development. Jawa was first of originated by Sun
Advertisements
 

 

 

DMCA.com