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

📄 stockdemo.java

📁 现在在国外大学里最流行的java学习软件,同时还有大量的example,在名为project的文件里.安装好后用bluej打开peoject的例子,可以进行你想要的任何变化.同时可以了解大量的源码
💻 JAVA
字号:
/** * Demonstrate the StockManager and Product classes. * The demonstration becomes properly functional as * the StockManager class is completed. *  * @author David J. Barnes and Michael Kolling * @version 2006.03.30 */public class StockDemo{    // The stock manager.    private StockManager manager;    /**     * Create a StockManager and populate it with a few     * sample products.     */    public StockDemo()    {        manager = new StockManager();        manager.addProduct(new Product(132, "Clock Radio"));        manager.addProduct(new Product(37,  "Mobile Phone"));        manager.addProduct(new Product(23,  "Microwave Oven"));    }        /**     * Provide a very simple demonstration of how a StockManager     * might be used. Details of one product are shown, the     * product is restocked, and then the details are shown again.     */    public void demo()    {        // Show details of all of the products.        manager.printProductDetails();        // Take delivery of 5 items of one of the products.        manager.delivery(132, 5);        manager.printProductDetails();    }        /**     * Show details of the given product. If found,     * its name and stock quantity will be shown.     * @param id The ID of the product to look for.     */    public void showDetails(int id)    {        Product product = getProduct(id);        if(product != null) {            System.out.println(product.toString());        }    }        /**     * Sell one of the given item.     * Show the before and after status of the product.     * @param id The ID of the product being sold.     */    public void sellProduct(int id)    {        Product product = getProduct(id);                if(product != null) {            showDetails(id);            product.sellOne();            showDetails(id);        }    }        /**     * Get the product with the given id from the manager.     * An error message is printed if there is no match.     * @param id The ID of the product.     * @return The Product, or null if no matching one is found.     */    public Product getProduct(int id)    {        Product product = manager.findProduct(id);        if(product == null) {            System.out.println("Product with ID: " + id +                               " is not recognised.");        }        return product;    }    /**     * @return The stock manager.     */    public StockManager getManager()    {        return manager;    }}

⌨️ 快捷键说明

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