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