⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gourmetcoffee.java

📁 ssd3 exercise2 的题目和答案
💻 JAVA
字号:
// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   GourmetCoffee.java

import java.io.*;
import java.text.NumberFormat;
import java.util.Iterator;

public class GourmetCoffee
{

    public static void main(String args[])
        throws IOException
    {
        GourmetCoffee gourmetcoffee = new GourmetCoffee(load());
        gourmetcoffee.run();
    }

    private static Catalog load()
    {
        Catalog catalog1 = new Catalog();
        catalog1.addProduct(new Coffee("C001", "Colombia, Whole, 1 lb", 17.989999999999998D, "Colombia", "Medium", "Rich and Hearty", "Rich", "Medium", "Full"));
        catalog1.addProduct(new Coffee("C002", "Colombia, Ground, 1 lb", 18.75D, "Colombia", "Medium", "Rich and Hearty", "Rich", "Medium", "Full"));
        catalog1.addProduct(new Coffee("C003", "Italian Roasts, Whole, 1 lb", 16.800000000000001D, "Latin American Blend", "Italian Roast", "Dark and heavy", "Intense", "Low", "Medium"));
        catalog1.addProduct(new Coffee("C004", "Italian Roasts, Ground, 1 lb", 17.550000000000001D, "Latin American Blend", "Italian Roast", "Dark and heavy", "Intense", "Low", "Medium"));
        catalog1.addProduct(new Coffee("C005", "French Roasts, Whole, 1 lb", 16.800000000000001D, "Latin American Blend", "French Roast", "Bittersweet, full intense", "Intense, full", "None", "Medium"));
        catalog1.addProduct(new Coffee("C006", "French Roasts, Ground, 1 lb", 17.550000000000001D, "Latin American Blend", "French Roast", "Bittersweet, full intense", "Intense, full", "None", "Medium"));
        catalog1.addProduct(new Coffee("C007", "Guatemala, Ground, 1 lb", 17.989999999999998D, "Guatemala", "Medium", "Rich and complex", "Spicy", "Medium to high", "Medium to full"));
        catalog1.addProduct(new Coffee("C008", "Guatemala, Ground, 1 lb", 18.75D, "Guatemala", "Medium", "Rich and complex", "Spicy", "Medium to high", "Medium to full"));
        catalog1.addProduct(new Coffee("C009", "Guatemala, Whole, 1 lb", 19.989999999999998D, "Sumatra", "Medium", "Vibrant and powdery", "Like dark chocolate", "Gentle", "Rich and full"));
        catalog1.addProduct(new Coffee("C010", "Guatemala, Ground, 1 lb", 20.5D, "Sumatra", "Medium", "Vibrant and powdery", "Like dark chocolate", "Gentle", "Rich and full"));
        catalog1.addProduct(new Coffee("C011", "Special Blend, Whole, 1 lb", 16.800000000000001D, "Latin American Blend", "Dark roast", "Full, roasted flavor", "Hearty", "Bold and rich", "Full"));
        catalog1.addProduct(new Coffee("C012", "Special Blend, Ground, 1 lb", 17.550000000000001D, "Latin American Blend", "Dark roast", "Full, roasted flavor", "Hearty", "Bold and rich", "Full"));
        catalog1.addProduct(new CoffeeBrewer("B001", "Home Coffee Brewer", 150D, "Brewer 100", "Pourover", 6));
        catalog1.addProduct(new CoffeeBrewer("B002", "Coffee Brewer, 2 Warmers", 200D, "Brewer 200", "Pourover", 12));
        catalog1.addProduct(new CoffeeBrewer("B003", "Coffee Brewer, 3 Warmers", 280D, "Brewer 210", "Pourover", 12));
        catalog1.addProduct(new CoffeeBrewer("B004", "Commercial Brewer, 20 cups", 380D, "Quick Coffee 100", "Automatic", 20));
        catalog1.addProduct(new CoffeeBrewer("B005", "Commercial Brewer, 40 cups", 480D, "Quick Coffee 200", "Automatic", 40));
        catalog1.addProduct(new Product("A001", "Almond Flavored Syrup", 9D));
        catalog1.addProduct(new Product("A002", "Irish Creme Flavored Syrup", 9D));
        catalog1.addProduct(new Product("A003", "Mint Flavored syrup", 9D));
        catalog1.addProduct(new Product("A004", "Caramel Flavored Syrup", 9D));
        catalog1.addProduct(new Product("A005", "Gourmet Coffee Cookies", 12D));
        catalog1.addProduct(new Product("A006", "Gourmet Coffee Travel Thermo", 18D));
        catalog1.addProduct(new Product("A007", "Gourmet Coffee Ceramic Mug", 8D));
        catalog1.addProduct(new Product("A008", "Gourmet Coffee 12 Cup Filters", 15D));
        catalog1.addProduct(new Product("A009", "Gourmet Coffee 36 Cup Filters", 45D));
        return catalog1;
    }

    private GourmetCoffee(Catalog catalog1)
    {
        catalog = catalog1;
        currentOrder = new Order();
        sales = new Sales();
    }

    private void run()
        throws IOException
    {
        for(int i = getChoice(); i != 0; i = getChoice())
        {
            if(i == 1)
            {
                displayCatalog();
                continue;
            }
            if(i == 2)
            {
                displayProductInfo();
                continue;
            }
            if(i == 3)
            {
                displayOrder();
                continue;
            }
            if(i == 4)
            {
                addModifyProduct();
                continue;
            }
            if(i == 5)
            {
                removeProduct();
                continue;
            }
            if(i == 6)
            {
                saleOrder();
                continue;
            }
            if(i == 7)
                displayOrdersSold();
        }

    }

    private int getChoice()
        throws IOException
    {
_L1:
        int i;
        stdErr.println();
        stdErr.print("[0]  Quit\n[1]  Display catalog\n[2]  Display product\n[3]  Display current order\n[4]  Add|modify product to|in current order\n[5]  Remove product from current order\n[6]  Register sale of current order\n[7]  Display sales\nchoice> ");
        stdErr.flush();
        i = Integer.parseInt(stdIn.readLine());
        stdErr.println();
        if(0 > i || 7 < i)
            try
            {
                stdErr.println((new StringBuilder()).append("Invalid choice:  ").append(i).toString());
            }
            catch(NumberFormatException numberformatexception)
            {
                stdErr.println(numberformatexception);
            }
        else
            return i;
          goto _L1
    }

    private void displayCatalog()
    {
        int i = catalog.getNumberOfProducts();
        if(i == 0)
        {
            stdErr.println("The catalog is empty");
        } else
        {
            Product product;
            for(Iterator iterator = catalog.iterator(); iterator.hasNext(); stdOut.println((new StringBuilder()).append(product.getCode()).append(" ").append(product.getDescription()).toString()))
                product = (Product)iterator.next();

        }
    }

    private void displayProductInfo()
        throws IOException
    {
        Product product = readProduct();
        if(product != null)
        {
            stdOut.println((new StringBuilder()).append("  Description: ").append(product.getDescription()).toString());
            stdOut.println((new StringBuilder()).append("  Price: ").append(product.getPrice()).toString());
            if(product instanceof Coffee)
            {
                Coffee coffee = (Coffee)product;
                stdOut.println((new StringBuilder()).append("  Origin: ").append(coffee.getOrigin()).toString());
                stdOut.println((new StringBuilder()).append("  Roast: ").append(coffee.getRoast()).toString());
                stdOut.println((new StringBuilder()).append("  Flavor: ").append(coffee.getFlavor()).toString());
                stdOut.println((new StringBuilder()).append("  Aroma: ").append(coffee.getAroma()).toString());
                stdOut.println((new StringBuilder()).append("  Acidity: ").append(coffee.getAcidity()).toString());
                stdOut.println((new StringBuilder()).append("  Body: ").append(coffee.getBody()).toString());
            } else
            if(product instanceof CoffeeBrewer)
            {
                CoffeeBrewer coffeebrewer = (CoffeeBrewer)product;
                stdOut.println((new StringBuilder()).append("  Model: ").append(coffeebrewer.getModel()).toString());
                stdOut.println((new StringBuilder()).append("  Water Supply: ").append(coffeebrewer.getWaterSupply()).toString());
                stdOut.println((new StringBuilder()).append("  Number of Cups: ").append(coffeebrewer.getNumberOfCups()).toString());
            }
        } else
        {
            stdErr.println("There are no products with that code");
        }
    }

    private void displayOrder()
    {
        int i = currentOrder.getNumberOfItems();
        if(i == 0)
        {
            stdErr.println("The current order is empty");
        } else
        {
            OrderItem orderitem;
            for(Iterator iterator = currentOrder.iterator(); iterator.hasNext(); stdOut.println(orderitem.toString()))
                orderitem = (OrderItem)iterator.next();

            stdOut.println((new StringBuilder()).append("Total: ").append(CURRENCY.format(currentOrder.getTotalCost())).toString());
        }
    }

    private void addModifyProduct()
        throws IOException
    {
        Product product = readProduct();
        if(product != null)
        {
            int i = readQuantity();
            OrderItem orderitem = currentOrder.getItem(product);
            if(orderitem == null)
            {
                currentOrder.addItem(new OrderItem(product, i));
                stdOut.println((new StringBuilder()).append("The product ").append(product.getCode()).append(" has been added").toString());
            } else
            {
                orderitem.setQuantity(i);
                stdOut.println((new StringBuilder()).append("The quantity of the product ").append(product.getCode()).append(" has been modified").toString());
            }
        } else
        {
            stdErr.println("There are no products with that code");
        }
    }

    private void removeProduct()
        throws IOException
    {
        Product product = readProduct();
        if(product != null)
        {
            OrderItem orderitem = currentOrder.getItem(product);
            if(orderitem != null)
            {
                currentOrder.removeItem(orderitem);
                stdOut.println((new StringBuilder()).append("The product ").append(product.getCode()).append(" has been removed from the current order").toString());
            } else
            {
                stdErr.println("There are no products in the current order with that code");
            }
        } else
        {
            stdErr.println("There are no products with that code");
        }
    }

    private void saleOrder()
    {
        if(currentOrder.getNumberOfItems() > 0)
        {
            sales.addOrder(currentOrder);
            currentOrder = new Order();
            stdOut.println("The sale of the order has been registered");
        } else
        {
            stdErr.println("The current order is empty");
        }
    }

    private void displayOrdersSold()
    {
        int i = sales.getNumberOfOrders();
        if(i != 0)
        {
            int j = 1;
            Order order;
            for(Iterator iterator = sales.iterator(); iterator.hasNext(); stdOut.println((new StringBuilder()).append("   Total: ").append(CURRENCY.format(order.getTotalCost())).toString()))
            {
                order = (Order)iterator.next();
                stdOut.println((new StringBuilder()).append("Order ").append(j++).toString());
                OrderItem orderitem;
                for(Iterator iterator1 = order.iterator(); iterator1.hasNext(); stdOut.println((new StringBuilder()).append("   ").append(orderitem.toString()).toString()))
                    orderitem = (OrderItem)iterator1.next();

            }

        } else
        {
            stdErr.println("There are no sales");
        }
    }

    private Product readProduct()
        throws IOException
    {
        stdErr.print("Product code> ");
        stdErr.flush();
        return catalog.getProduct(stdIn.readLine());
    }

    private int readQuantity()
        throws IOException
    {
_L1:
        int i;
        stdErr.print("Quantity> ");
        stdErr.flush();
        i = Integer.parseInt(stdIn.readLine());
        if(i <= 0)
            try
            {
                stdErr.println("Invalid input. Please enter a positive integer");
            }
            catch(NumberFormatException numberformatexception)
            {
                stdErr.println(numberformatexception);
            }
        else
            return i;
          goto _L1
    }

    private static BufferedReader stdIn;
    private static PrintWriter stdOut;
    private static PrintWriter stdErr;
    private static final String DELIMITER = "_";
    private static final NumberFormat CURRENCY = NumberFormat.getCurrencyInstance();
    private Catalog catalog;
    private Order currentOrder;
    private Sales sales;

    static 
    {
        stdIn = new BufferedReader(new InputStreamReader(System.in));
        stdOut = new PrintWriter(System.out, true);
        stdErr = new PrintWriter(System.err, true);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -