/*  Class Stock_Item represents one type of stock item with a */
/*  particular quantity on hand in the inventory.  Stock_Item */
/*  objects hold a reference to the Manager object that is    */
/*  responsible for reordering the item as needed.            */

class Stock_Item {

   private int inventory = 0;
   private String name;
   private Manager product_buyer;

   // Creates a new Stock_Item object with the specified
   // controlling Manager and product name.
   public Stock_Item (Manager controller, String product_name) {
      name = product_name;
      product_buyer = controller;
   }
   
   // Returns the name of the product.
   public String brand () {
      return name;
   }

   // Attempts to purchase the specified amount of the
   // stock item.  If there is not enough in inventory, the
   // item is restocked by invoking the order_stock method
   // of the appropriate Manager object.
   public boolean buy (int amount) {

      boolean success = false;

      if ( amount <= inventory ) {
         inventory = inventory - amount;
         success = true;
      }
      else
         product_buyer.order_stock (this);

      return success;
   }

   //  Adds the indicated amount of this stock item to the
   //  inventory.
   public void replenish (int amount) {
      inventory = inventory + amount;
   }
}  // class Stock_Item

