ch7.catalog
Class ShoppingCart<Item>

java.lang.Object
  extended by ch7.catalog.ShoppingCart<Item>
Type Parameters:
Item -

public class ShoppingCart<Item>
extends java.lang.Object

A generic class for a shopping cart.

The class can store any type of item. It allows for adding an item and clearing all items. Additional helpers have been added just to show that the cart can have any kind of additional functionality.


Constructor Summary
ShoppingCart()
          Creates a new instance of ShoppingCart
 
Method Summary
 void addItem(Item item)
          Add an item to the cart.
 void addTotal(double amount)
          Add an amount to the total.
 int getCount()
          Accessor for the count of items in the cart.
 java.util.List<Item> getItems()
          Retrieve a list of all the items in the cart.
 double getTotal()
          Retrieve the total price for the cart.
 java.lang.String getTotalAsCurrency()
          Retrieve the total as currency.
 void incrCount()
          Increment the count.
 void resetItems()
          Release all the items from the shopping cart.
 void setCount(int count)
          Set the count for the cart.
 void setItems(java.util.List<Item> items)
          Set all the items in the shopping cart from a list of items.
 void setTotal(double total)
          Set the total price for the cart.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShoppingCart

public ShoppingCart()
Creates a new instance of ShoppingCart

Method Detail

resetItems

public void resetItems()
Release all the items from the shopping cart.


setItems

public void setItems(java.util.List<Item> items)
Set all the items in the shopping cart from a list of items.

Parameters:
items - Element data from the request

getItems

public java.util.List<Item> getItems()
Retrieve a list of all the items in the cart.

Returns:
The list of items

addItem

public void addItem(Item item)
Add an item to the cart.

Parameters:
item - Element data from the request

setTotal

public void setTotal(double total)
Set the total price for the cart.

Parameters:
total - Element data from the request

getTotal

public double getTotal()
Retrieve the total price for the cart.

Returns:
total

setCount

public void setCount(int count)
Set the count for the cart.

The count could be different from the actual number of items in the cart, if a feature is added to allow multiple numbers of an item.

Parameters:
count - Element data from the request

getCount

public int getCount()
Accessor for the count of items in the cart.

Returns:
count.

addTotal

public void addTotal(double amount)
Add an amount to the total.

Parameters:
amount - Element data from the request

getTotalAsCurrency

public java.lang.String getTotalAsCurrency()
Retrieve the total as currency.

Returns:
currency as a string

incrCount

public void incrCount()
Increment the count.