FileDocCategorySizeDatePackage
ShoppingCart.javaAPI DocExample2026Tue Dec 12 18:59:40 GMT 2000cart

ShoppingCart

public class ShoppingCart extends Object

Fields Summary
Hashtable
items
int
numberOfItems
Constructors Summary
public ShoppingCart()


      
        items = new Hashtable();
    
Methods Summary
public voidadd(java.lang.String bookId, database.BookDetails book)

        if(items.containsKey(bookId)) {
            ShoppingCartItem scitem = (ShoppingCartItem) items.get(bookId);
            scitem.incrementQuantity();
        } else {
            ShoppingCartItem newItem = new ShoppingCartItem(book);
            items.put(bookId, newItem);
        }

        numberOfItems++;
    
public voidclear()

        items.clear();
        numberOfItems = 0;
    
protected voidfinalize()

        items.clear();
    
public java.util.EnumerationgetItems()

        return items.elements();
    
public intgetNumberOfItems()

        return numberOfItems;
    
public voidremove(java.lang.String bookId)

        if(items.containsKey(bookId)) {
            ShoppingCartItem scitem = (ShoppingCartItem) items.get(bookId);
            scitem.decrementQuantity();

            if(scitem.getQuantity() <= 0)
                items.remove(bookId);

            numberOfItems--;
        }