package coreservlets; import java.util.*; /** 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. */ public class ShoppingCart { private Vector itemsOrdered; /** Builds an empty shopping cart. */ public ShoppingCart() { itemsOrdered = new Vector(); } /** Returns Vector of ItemOrder entries giving * Item and number ordered. */ public Vector getItemsOrdered() { return(itemsOrdered); } /** 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. */ public synchronized void addItem(String itemID) { ItemOrder order; for(int i=0; i