/** * Demonstrate the StockManager and Product classes. * The demonstration becomes properly functional as * the StockManager class is completed. * * @author David J. Barnes and Michael Kolling, modified by Bob Broeg * @version 2003.01.10 */ 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", 5)); manager.addProduct(new Product(37, "Mobile Phone", 3)); manager.addProduct(new Product(23, "Microwave Oven", 7)); manager.addProduct(new Product(15, "Coffee Maker", 6)); manager.addProduct(new Product(59, "Computer Printer", 8)); manager.addProduct(new Product(275, "Washing Machine", 2)); manager.addProduct(new Product(76, "Hair Dryer", 25)); manager.addProduct(new Product(48, "DVD Player", 9)); manager.addProduct(new Product(84, "Outdoor Gas Grill", 12)); manager.addProduct(new Product(99, "Flat Panel TV", 4)); } /** * 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() { System.out.println(); System.out.println( "***Printing the Product Details" ); manager.printProductDetails(); System.out.println(); System.out.println( "***Finding some items" ); System.out.println( "Looking for item with ID 15" ); Product temp = manager.findProduct( 15 ); if( temp != null ) { System.out.println( "Found it: " + temp ); } else { System.out.println( "Item not found" ); } System.out.println( "Looking for item with ID 12" ); temp = manager.findProduct( 12 ); if( temp != null ) { System.out.println( "Found it: " + temp ); } else { System.out.println( "Item not found" ); } System.out.println(); System.out.println( "***Low Inventory Report--Less than 6 items" ); manager.lowInventory( 6 ); System.out.println(); System.out.println( "***Selling some items" ); manager.sellProduct( 84 ); manager.sellProduct( 76 ); manager.sellProduct( 48 ); manager.sellProduct( 99 ); manager.sellProduct( 84 ); manager.sellProduct( 8 ); manager.sellProduct( 76 ); manager.sellProduct( 15 ); System.out.println(); System.out.println( "***Final inventory report" ); manager.printProductDetails(); System.out.println(); } /** * 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 = manager.findProduct(id); if(product != null) { System.out.println(product); } else { System.out.println("Product number " + id + " is not recognised."); } } /** * @return The stock manager. */ public StockManager getManager() { return manager; } }