Class Cart
java.lang.Object
|
+--Cart
- public class Cart
- extends java.lang.Object
Invariant:
For each item, quantity in cart plus quantity recorded in database
equals total current inventory.
This is a single thread class. Only one of the public functions
may be active at a time.
- Since:
- 0.0
Constructor Summary |
Cart(Customer c)
Creates an empty cart for customer c. |
Method Summary |
boolean |
addToCart(java.lang.Object item,
int quantity)
|
Enumeration |
contents()
Returns a sequence of the cart's contents. |
void |
removeFromCart(java.lang.Object item)
If any quantity of the item is in the cart, it is removed and returned
to the main DB. |
int |
totalPrice()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Cart
public Cart(Customer c)
- Creates an empty cart for customer c.
- Parameters:
c
- (if customer objects have states in which carts cannot be created
for them, I would assert the precondition for an acceptable state here.
The reason for having the customer at all is just to filter out
demands for too many copies of an item.)- See Also:
Customer
contents
public Enumeration contents()
- Returns a sequence of the cart's contents.
- Returns:
- an enumeration object for traversing the entire cart contents
in alphabetical order by title.
addToCart
public boolean addToCart(java.lang.Object item,
int quantity)
- Parameters:
quantity
- This must be positive and below the customer's per item limit.item
- The item must be on our current stock list.- Returns:
- True iff current available inventory of item is no less than quantity.
The specified quantity of item is removed from the central DB
and added to this cart.
removeFromCart
public void removeFromCart(java.lang.Object item)
- If any quantity of the item is in the cart, it is removed and returned
to the main DB.
totalPrice
public int totalPrice()
- Returns:
- The sum of the prices of all of the items in the cart.