Creating a Shopping Cart

The shopping cart we are creating provides transient storage to hold any number of items selected by the user. It provides the functionality to add items, remove items, and change the quantity of an item in the cart. In a normal application you would create an object that would represent a cart item, but for this example we are just adding the properties of an item. Listing 13.1 contains the source for the shopping cart.

Code Listing 13.1. ShoppingCart.java
 import java.lang.String; import java.lang.Integer; import java.lang.Float; import java.util.Hashtable; import java.util.Enumeration; public class ShoppingCart { protected Hashtable items = new Hashtable(); public ShoppingCart() { } /** * Add a new item to the shopping ...

Get Pure Java Server Pages™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.