Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
222
Chapter 9 Session Tracking
Listing 9.6 ShoppingCart.java (continued)
* is positive, sets it. If designated number is 0
* (or, negative due to a user input error), deletes
* item from cart.
*/
public synchronized void setNumOrdered(String itemID,
int numOrdered) {
ItemOrder order;
for(int i=0; i
order = (ItemOrder)itemsOrdered.elementAt(i);
if (order.getItemID().equals(itemID)) {
if (numOrdered <= 0) {
itemsOrdered.removeElementAt(i);
} else {
order.setNumItems(numOrdered);
}
return;
}
}
ItemOrder newOrder =
new ItemOrder(Catalog.getItem(itemID));
itemsOrdered.addElement(newOrder);
}
}
Listing 9.7 Item.java
package coreservlets;
/** Describes a catalog item for on line store. The itemID
* uniquely identifies the item, the short description
* gives brief info like the book title and author,
* the long description describes the item in a couple
* of sentences, and the cost gives the current per item price.
* Both the short and long descriptions can contain HTML
* markup.
*/
public class Item {
private String itemID;
private String shortDescription;
private String longDescription;
private double cost;
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved