KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > stateful_deployment_descriptor > bean > ShoppingCartBean


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.tutorial.stateful_deployment_descriptor.bean;
8
9 import java.io.Serializable JavaDoc;
10 import java.util.HashMap JavaDoc;
11
12 public class ShoppingCartBean implements ShoppingCart, Serializable JavaDoc
13 {
14    private HashMap JavaDoc<String JavaDoc, Integer JavaDoc> cart = new HashMap JavaDoc<String JavaDoc, Integer JavaDoc>();
15
16    public void buy(String JavaDoc product, int quantity)
17    {
18       if (cart.containsKey(product))
19       {
20          int currq = cart.get(product);
21          currq += quantity;
22          cart.put(product, currq);
23       }
24       else
25       {
26          cart.put(product, quantity);
27       }
28    }
29
30    public HashMap JavaDoc<String JavaDoc, Integer JavaDoc> getCartContents()
31    {
32       return cart;
33    }
34
35    public void checkout()
36    {
37       System.out.println("To be implemented");
38    }
39 }
40
Popular Tags