Coffee shop

Coffee shop

How would i write a program that says's..Welcome to Wings Coffee Shop. We have a great list items on our menu.Would you like to see items sorted by name or price? (n/p):n Item Name Price Bagel $1.25 Water $2.00 Coffee $1.00 Donut $0.75 Milk $1.50

View Answers

March 11, 2011 at 12:44 PM

import java.util.*;

class Item {
        String name;
        double price;
        Item(String name,double price){
        this.name=name;
        this.price=price;
        }
        public void setName(String name){
                this.name = name;
        }
        public String getName() {
                return name;
        }
        public void setPrice(double price) {
                this.price = price;
        }
        public double getPrice(){
                return price;
        }
       }
class NameComparator implements Comparator{
    public int compare(Object o1, Object o2){    
       String name1 = ((Item)o1).getName();        
       String name2 = ((Item)o2).getName();
       return name1.compareTo(name2);
 }
}
class PriceComparator implements Comparator{
  public int compare(Object o1, Object o2){
 if (((Item)o1).getPrice() < ((Item)o2).getPrice()) return -1;
        if (((Item)o1).getPrice() > ((Item)o2).getPrice()) return 1;
        return 0;
    } 
}
class  CoffeeDriver
{
    static ArrayList<Item> list=new ArrayList<Item>();
    public static void sortName(){
    Collections.sort(list,new NameComparator());
                for(Item data: list){
               System.out.println(data.getName()+"\t "+data.getPrice());
    }
    }
    public static void sortPrice(){
    Collections.sort(list,new PriceComparator());
                for(Item data: list){
               System.out.println(data.getName()+"\t "+data.getPrice());
    }
    }
    public static void main(String[] args) 
    {
        Scanner input=new Scanner(System.in);

               list.add(new Item("Bagel",1.25));
               list.add(new Item("Water",2.00));
               list.add(new Item("Coffee",1.00));
               list.add(new Item("Donut",0.75));
               list.add(new Item("Milk",1.50));
               System.out.println("Sorted By Name");
               System.out.println("Sorted By Price");
               System.out.println("Exit");
                boolean exit=false;
               do{
               System.out.print("Enter your choice: ");
               int choice=input.nextInt();

             switch(choice){
             case 1:
                 sortName();
                 break;
             case 2: 
                 sortPrice();
             break;
             case 3:
                 exit=true;
             break;
             default:
                 System.out.println("Invalid");
         }
               }
         while(!exit);
    }
    }









Related Tutorials/Questions & Answers:
Coffee shop
Coffee shop  How would i write a program that says's..Welcome to Wings Coffee Shop. We have a great list items on our menu.Would you like to see... $2.00 Coffee $1.00 Donut $0.75 Milk $1.50   
cofee shop
)); list.add(new Item("Coffee",1.00)); list.add(new
Advertisements
ModuleNotFoundError: No module named 'coffee'
ModuleNotFoundError: No module named 'coffee'  Hi, My Python... 'coffee' How to remove the ModuleNotFoundError: No module named 'coffee'... to install padas library. You can install coffee python with following command
ModuleNotFoundError: No module named 'coffee'
ModuleNotFoundError: No module named 'coffee'  Hi, My Python... 'coffee' How to remove the ModuleNotFoundError: No module named 'coffee'... to install padas library. You can install coffee python with following command
Flower Shop Ordering To Go
Flower Shop Ordering To Go   Create a flower shop application which deals in flower objects and use those flower objects in a bouquet which can then be sold. The flower object has a flower name, color, quantity. Adding
Version of ca.genovese>coffee-cats dependency
List of Version of ca.genovese>coffee-cats dependency
ModuleNotFoundError: No module named 'coffee-ninja'
ModuleNotFoundError: No module named 'coffee-ninja'  Hi, My Python... 'coffee-ninja' How to remove the ModuleNotFoundError: No module named 'coffee-ninja' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Flask-Coffee'
ModuleNotFoundError: No module named 'Flask-Coffee'  Hi, My Python... 'Flask-Coffee' How to remove the ModuleNotFoundError: No module named 'Flask-Coffee' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'npm-coffee'
ModuleNotFoundError: No module named 'npm-coffee'  Hi, My Python... 'npm-coffee' How to remove the ModuleNotFoundError: No module named 'npm-coffee' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'sphinxcontrib-coffee'
ModuleNotFoundError: No module named 'sphinxcontrib-coffee'  Hi...: No module named 'sphinxcontrib-coffee' How to remove the ModuleNotFoundError: No module named 'sphinxcontrib-coffee' error? Thanks   Hi
ModuleNotFoundError: No module named 'coffee-boat'
ModuleNotFoundError: No module named 'coffee-boat'  Hi, My Python... 'coffee-boat' How to remove the ModuleNotFoundError: No module named 'coffee-boat' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'coffee-ninja'
ModuleNotFoundError: No module named 'coffee-ninja'  Hi, My Python... 'coffee-ninja' How to remove the ModuleNotFoundError: No module named 'coffee-ninja' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-coffee'
ModuleNotFoundError: No module named 'django-coffee'  Hi, My... 'django-coffee' How to remove the ModuleNotFoundError: No module named 'django-coffee' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Flask-Coffee'
ModuleNotFoundError: No module named 'Flask-Coffee'  Hi, My Python... 'Flask-Coffee' How to remove the ModuleNotFoundError: No module named 'Flask-Coffee' error? Thanks   Hi, In your python
Computer shop mangerment
Computer shop mangerment   Part A You are supposed to write a class Computer to stores the computer id, description, brand, price, speed and another... of it. Part B Develop array based java program to help a local computer shop
ModuleNotFoundError: No module named 'api-shop'
ModuleNotFoundError: No module named 'api-shop'  Hi, My Python...-shop' How to remove the ModuleNotFoundError: No module named 'api-shop... to install padas library. You can install api-shop python with following
ModuleNotFoundError: No module named 'pizza-shop'
ModuleNotFoundError: No module named 'pizza-shop'  Hi, My Python... 'pizza-shop' How to remove the ModuleNotFoundError: No module named 'pizza-shop' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'Scarf-shop'
ModuleNotFoundError: No module named 'Scarf-shop'  Hi, My Python... 'Scarf-shop' How to remove the ModuleNotFoundError: No module named 'Scarf-shop' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'wagtail-shop'
ModuleNotFoundError: No module named 'wagtail-shop'  Hi, My Python... 'wagtail-shop' How to remove the ModuleNotFoundError: No module named 'wagtail-shop' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'api-shop'
ModuleNotFoundError: No module named 'api-shop'  Hi, My Python...-shop' How to remove the ModuleNotFoundError: No module named 'api-shop... to install padas library. You can install api-shop python with following
ModuleNotFoundError: No module named 'cmsplugin-shop'
ModuleNotFoundError: No module named 'cmsplugin-shop'  Hi, My... named 'cmsplugin-shop' How to remove the ModuleNotFoundError: No module named 'cmsplugin-shop' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-shop'
ModuleNotFoundError: No module named 'django-shop'  Hi, My Python... 'django-shop' How to remove the ModuleNotFoundError: No module named 'django-shop' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'Fulfil-Shop'
ModuleNotFoundError: No module named 'Fulfil-Shop'  Hi, My Python... 'Fulfil-Shop' How to remove the ModuleNotFoundError: No module named 'Fulfil-Shop' error? Thanks   Hi, In your python environment
Version of com.theoryinpractise>coffee-maven-plugin dependency
List of Version of com.theoryinpractise>coffee-maven-plugin dependency
ModuleNotFoundError: No module named 'django-sassy-coffee'
ModuleNotFoundError: No module named 'django-sassy-coffee'  Hi, My... named 'django-sassy-coffee' How to remove the ModuleNotFoundError: No module named 'django-sassy-coffee' error? Thanks   Hi
ModuleNotFoundError: No module named 'coffee-compressor-compiler'
ModuleNotFoundError: No module named 'coffee-compressor-compiler'  Hi...: No module named 'coffee-compressor-compiler' How to remove the ModuleNotFoundError: No module named 'coffee-compressor-compiler' error? Thanks
ModuleNotFoundError: No module named 'coffee-list-app'
ModuleNotFoundError: No module named 'coffee-list-app'  Hi, My... named 'coffee-list-app' How to remove the ModuleNotFoundError: No module named 'coffee-list-app' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django_coffee_table'
ModuleNotFoundError: No module named 'django_coffee_table'  Hi, My... named 'django_coffee_table' How to remove the ModuleNotFoundError: No module named 'django_coffee_table' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-sassy-coffee'
ModuleNotFoundError: No module named 'django-sassy-coffee'  Hi, My... named 'django-sassy-coffee' How to remove the ModuleNotFoundError: No module named 'django-sassy-coffee' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-base-shop'
ModuleNotFoundError: No module named 'django-base-shop'  Hi, My... named 'django-base-shop' How to remove the ModuleNotFoundError: No module named 'django-base-shop' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'django-base-shop'
ModuleNotFoundError: No module named 'django-base-shop'  Hi, My... named 'django-base-shop' How to remove the ModuleNotFoundError: No module named 'django-base-shop' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'django-shop-netaxept'
ModuleNotFoundError: No module named 'django-shop-netaxept'  Hi...: No module named 'django-shop-netaxept' How to remove the ModuleNotFoundError: No module named 'django-shop-netaxept' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-shop-payer-backend'
ModuleNotFoundError: No module named 'django-shop-payer-backend'  Hi...: No module named 'django-shop-payer-backend' How to remove the ModuleNotFoundError: No module named 'django-shop-payer-backend' error? Thanks  
ModuleNotFoundError: No module named 'django-shop-paypal'
ModuleNotFoundError: No module named 'django-shop-paypal'  Hi, My... named 'django-shop-paypal' How to remove the ModuleNotFoundError: No module named 'django-shop-paypal' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'django-shop-simplenotifications'
ModuleNotFoundError: No module named 'django-shop-simplenotifications' ...: ModuleNotFoundError: No module named 'django-shop-simplenotifications' How to remove the ModuleNotFoundError: No module named 'django-shop-simplenotifications' error
ModuleNotFoundError: No module named 'django-simple-shop'
ModuleNotFoundError: No module named 'django-simple-shop'  Hi, My... named 'django-simple-shop' How to remove the ModuleNotFoundError: No module named 'django-simple-shop' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'django-wagtail-shop'
ModuleNotFoundError: No module named 'django-wagtail-shop'  Hi, My... named 'django-wagtail-shop' How to remove the ModuleNotFoundError: No module named 'django-wagtail-shop' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-wagtail-shop'
ModuleNotFoundError: No module named 'django-wagtail-shop'  Hi, My... named 'django-wagtail-shop' How to remove the ModuleNotFoundError: No module named 'django-wagtail-shop' error? Thanks   Hi
ModuleNotFoundError: No module named 'ls-django-shop-categories'
ModuleNotFoundError: No module named 'ls-django-shop-categories'  Hi...: No module named 'ls-django-shop-categories' How to remove the ModuleNotFoundError: No module named 'ls-django-shop-categories' error? Thanks  
ModuleNotFoundError: No module named 'pixelcms-shop-server'
ModuleNotFoundError: No module named 'pixelcms-shop-server'  Hi...: No module named 'pixelcms-shop-server' How to remove the ModuleNotFoundError: No module named 'pixelcms-shop-server' error? Thanks   Hi
ModuleNotFoundError: No module named 'trytonzz_sale_shop'
ModuleNotFoundError: No module named 'trytonzz_sale_shop'  Hi, My... named 'trytonzz_sale_shop' How to remove the ModuleNotFoundError: No module named 'trytonzz_sale_shop' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'django-base-shop'
ModuleNotFoundError: No module named 'django-base-shop'  Hi, My... named 'django-base-shop' How to remove the ModuleNotFoundError: No module named 'django-base-shop' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'django-mp-shop'
ModuleNotFoundError: No module named 'django-mp-shop'  Hi, My... named 'django-mp-shop' How to remove the ModuleNotFoundError: No module named 'django-mp-shop' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-mp-shop-attrs'
ModuleNotFoundError: No module named 'django-mp-shop-attrs'  Hi...: No module named 'django-mp-shop-attrs' How to remove the ModuleNotFoundError: No module named 'django-mp-shop-attrs' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-mp-shop-comparison'
ModuleNotFoundError: No module named 'django-mp-shop-comparison'  Hi...: No module named 'django-mp-shop-comparison' How to remove the ModuleNotFoundError: No module named 'django-mp-shop-comparison' error? Thanks  
ModuleNotFoundError: No module named 'django-mp-shop-offers'
ModuleNotFoundError: No module named 'django-mp-shop-offers'  Hi...: No module named 'django-mp-shop-offers' How to remove the ModuleNotFoundError: No module named 'django-mp-shop-offers' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-mp-shop-orders'
ModuleNotFoundError: No module named 'django-mp-shop-orders'  Hi...: No module named 'django-mp-shop-orders' How to remove the ModuleNotFoundError: No module named 'django-mp-shop-orders' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-mp-shop-products'
ModuleNotFoundError: No module named 'django-mp-shop-products'  Hi...: No module named 'django-mp-shop-products' How to remove the ModuleNotFoundError: No module named 'django-mp-shop-products' error? Thanks   
ModuleNotFoundError: No module named 'django-mp-shop-wishlist'
ModuleNotFoundError: No module named 'django-mp-shop-wishlist'  Hi...: No module named 'django-mp-shop-wishlist' How to remove the ModuleNotFoundError: No module named 'django-mp-shop-wishlist' error? Thanks   
ModuleNotFoundError: No module named 'django-senex-shop'
ModuleNotFoundError: No module named 'django-senex-shop'  Hi, My... named 'django-senex-shop' How to remove the ModuleNotFoundError: No module named 'django-senex-shop' error? Thanks   Hi, In your

Ads