Order the Book

coreservlets
Class ShoppingCart

java.lang.Object
  |
  +--coreservlets.ShoppingCart

public class ShoppingCart
extends Object

A shopping cart data structure used to track orders. The OrderPage servlet associates one of these carts with each user session.

Taken from Core Servlets and JavaServer Pages from Prentice Hall and Sun Microsystems Press, http://www.coreservlets.com/. © 2000 Marty Hall; may be freely used or adapted.


Constructor Summary
ShoppingCart()
          Builds an empty shopping cart.
 
Method Summary
 void addItem(String itemID)
          Looks through cart to see if it already contains an order entry corresponding to item ID.
 Vector getItemsOrdered()
          Returns Vector of ItemOrder entries giving Item and number ordered.
 void setNumOrdered(String itemID, int numOrdered)
          Looks through cart to find order entry corresponding to item ID listed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShoppingCart

public ShoppingCart()
Builds an empty shopping cart.
Method Detail

getItemsOrdered

public Vector getItemsOrdered()
Returns Vector of ItemOrder entries giving Item and number ordered.

addItem

public void addItem(String itemID)
Looks through cart to see if it already contains an order entry corresponding to item ID. If it does, increments the number ordered. If not, looks up Item in catalog and adds an order entry for it.

setNumOrdered

public void setNumOrdered(String itemID,
                          int numOrdered)
Looks through cart to find order entry corresponding to item ID listed. If the designated number is positive, sets it. If designated number is 0 (or, negative due to a user input error), deletes item from cart.

Order the Book

Order
CSAJSP @ amazon.com

Return to Top-Level Source Code Archive