ch7.catalog
Class ShoppingCart<Item>

java.lang.Object
  extended by ch7.catalog.ShoppingCart<Item>

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

The bean for the shopping cart. The bean is generic: it does not matter what the actual data is. The shopping cart defines the operations that can be performed on the list of items that it stores.


Constructor Summary
ShoppingCart()
          Creates a new instance of ShoppingCart.
 
Method Summary
 void addItem(Item item)
          Mutator for the items element.
 void addTotal(double amount)
          Mutator for the total element.
 int getCount()
          Accessor for the count element.
 java.util.List<Item> getItems()
          Accessor for the items element.
 double getTotal()
          Accessor for the total element.
 java.lang.String getTotalAsCurrency()
          Accessor for the total element, formatted as currency.
 void incrCount()
          Mutator for the count element.
 void resetItems()
          Resets the shopping cart so that it is empty.
 void setCount(int count)
          Mutator for the count element.
 void setItems(java.util.List<Item> items)
          Mutator for the items element.
 void setTotal(double total)
          Mutator for the total element.
 
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()
Resets the shopping cart so that it is empty.


setItems

public void setItems(java.util.List<Item> items)
Mutator for the items element.

Parameters:
items - The new value to store in the items.

getItems

public java.util.List<Item> getItems()
Accessor for the items element.

Returns:
The current value of the items.

addItem

public void addItem(Item item)
Mutator for the items element. A new item is added.

Parameters:
item - Added to the list of items.

setTotal

public void setTotal(double total)
Mutator for the total element.

Parameters:
total - The new value to store in the total.

getTotal

public double getTotal()
Accessor for the total element.

Returns:
The current value of the total.

setCount

public void setCount(int count)
Mutator for the count element.

Parameters:
count - The new value to store in the count.

getCount

public int getCount()
Accessor for the count element.

Returns:
The current value of the count.

addTotal

public void addTotal(double amount)
Mutator for the total element. The amount is added to the total.

Parameters:
amount - Added to the current total.

getTotalAsCurrency

public java.lang.String getTotalAsCurrency()
Accessor for the total element, formatted as currency.

Returns:
The current value of the total, formatted as currency.

incrCount

public void incrCount()
Mutator for the count element. The count is incremented by one.