Class Grocery

java.lang.Object
  extended by Grocery

public class Grocery
extends Object

Grocery class managing items sold at the grocery

Version:
1.0
Author:
JP Vergara

Constructor Summary
Grocery(double startCash)
          Constructor for a Grocery object.
 
Method Summary
 void carryItem(String itemName, String unitName, double buyPrice, double sellPrice)
          Include an item to be carried in the grocery.
 double getCashOnHand()
          Returns cash on hand in the grocery.
 int getItemStock(String itemName)
          Returns the stock level for the given item.
 String getUnitName(String itemName)
          Returns the unit name for the given item.
 void printInventory()
          Prints an inventory list for all items.
 void receiveShipment(String itemName, int qty)
          Receive a shipment for a particular item.
 void sellItem(String itemName, int qty)
          Sell some number of units for a particular item.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Grocery

public Grocery(double startCash)
Constructor for a Grocery object.

Parameters:
startCash - initial cash on hand
Method Detail

carryItem

public void carryItem(String itemName,
                      String unitName,
                      double buyPrice,
                      double sellPrice)
Include an item to be carried in the grocery. Create the item object and include it in the array or array list.

Parameters:
itemName - name of the item (e.g., "Bread")
unitName - unit name for the item (e.g., "loaves" )
buyPrice - buying price for the item
sellPrice - selling price for the item

getCashOnHand

public double getCashOnHand()
Returns cash on hand in the grocery.

Returns:
cash on hand

getItemStock

public int getItemStock(String itemName)
Returns the stock level for the given item. If the item does not exist, return 0

Parameters:
itemName - name of the item
Returns:
stock

getUnitName

public String getUnitName(String itemName)
Returns the unit name for the given item. If the item does not exist, return "units"

Parameters:
itemName - name of the item
Returns:
unit name

printInventory

public void printInventory()
Prints an inventory list for all items. For each item, the name, stock level, and unit name is indicated (e.g., "Coke: 5 cans" )


receiveShipment

public void receiveShipment(String itemName,
                            int qty)
Receive a shipment for a particular item. Causes stock for that item to increase and causes cash on hand for the grocery to decrease. Do nothing or print an error message if the item is not carried in the grocery or if there is not enough cash.

Parameters:
itemName - name of the item
qty - number of units of the item in the shipment

sellItem

public void sellItem(String itemName,
                     int qty)
Sell some number of units for a particular item. Causes stock for that item to decrease and causes cash on hand for the grocery to increase. Do nothing/print an error message if the item is not carried in the grocery or if there is not enough stock.

Parameters:
itemName - name of the item
qty - number of units of the item to be sold