FileDocCategorySizeDatePackage
CartBean.javaAPI DocExample1477Thu Jun 28 16:14:16 BST 2001com.ora.jsp.beans.shopping

CartBean

public class CartBean extends Object implements Serializable
This class represents a shopping cart. It holds a list of products.
author
Hans Bergsten, Gefion software
version
1.0

Fields Summary
private Vector
cart
Constructors Summary
Methods Summary
public java.util.EnumerationgetProducts()
Returns the product list.

return
an Enumeration of ProductBeans

        return cart.elements();
    
public floatgetTotal()
Returns the total price for all products in the cart

return
the total price

        float total = 0;
        Enumeration prods = getProducts();
        while (prods.hasMoreElements()) {
            ProductBean product = (ProductBean) prods.nextElement();
            float price = product.getPrice();
            total += price;
        }
        return total;
    
public booleanisEmpty()
Returns true if the cart is empty

return
true if the cart is empty

        return cart.size() == 0;
    
public voidsetProduct(ProductBean product)
Adds a product to the cart, if it's not already there.

param
product the ProductBean


                        
        
        if (product != null && cart.indexOf(product) == -1) {
            cart.addElement(product);
        }