KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > jpetstore > domain > CartItem


1 package com.ibatis.jpetstore.domain;
2
3 import java.io.Serializable JavaDoc;
4 import java.math.BigDecimal JavaDoc;
5
6
7 public class CartItem implements Serializable JavaDoc {
8
9   /* Private Fields */
10
11   private Item item;
12   private int quantity;
13   private boolean inStock;
14   private BigDecimal JavaDoc total;
15
16   /* JavaBeans Properties */
17
18   public boolean isInStock() {
19     return inStock;
20   }
21
22   public void setInStock(boolean inStock) {
23     this.inStock = inStock;
24   }
25
26   public BigDecimal JavaDoc getTotal() {
27     return total;
28   }
29
30   public Item getItem() {
31     return item;
32   }
33
34   public void setItem(Item item) {
35     this.item = item;
36     calculateTotal();
37   }
38
39   public int getQuantity() {
40     return quantity;
41   }
42
43   public void setQuantity(int quantity) {
44     this.quantity = quantity;
45     calculateTotal();
46   }
47
48   /* Public methods */
49
50   public void incrementQuantity() {
51     quantity++;
52     calculateTotal();
53   }
54
55   /* Private methods */
56
57   private void calculateTotal() {
58     if (item != null && item.getListPrice() != null) {
59       total = item.getListPrice().multiply(new BigDecimal JavaDoc(quantity));
60     } else {
61       total = null;
62     }
63   }
64
65 }
66
Popular Tags