FileDocCategorySizeDatePackage
CartBean.javaAPI DocExample1405Tue Feb 28 11:34:06 GMT 2006com.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
2.0

Fields Summary
private Vector
cart
Constructors Summary
Methods Summary
public ProductBean[]getProductList()
Returns the product list.

return
an Iterator of ProductBeans

	ProductBean[] products = null;
	synchronized(cart) {
	    products = new ProductBean[cart.size()];
	    cart.toArray(products);
	}
        return products;
    
public floatgetTotal()
Returns the total price for all products in the cart

return
the total price

        float total = 0;
        Iterator prods = cart.iterator();
        while (prods.hasNext()) {
            ProductBean product = (ProductBean) prods.next();
            float price = product.getPrice();
            total += price;
        }
        return total;
    
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);
        }