01: package net.ar.webonswing.petstore.model;
02:
03: import java.io.*;
04:
05: public class CartItem implements Serializable {
06: protected boolean inStock;
07: protected Item item;
08: protected int quantity;
09: protected long total;
10:
11: public CartItem() {
12: }
13:
14: protected void calculateTotal() {
15: if (item != null && item.getUnitCost() != 0)
16: total = (long) (item.getUnitCost() * quantity);
17: else
18: total = 0;
19: }
20:
21: public Item getItem() {
22: return item;
23: }
24:
25: public int getQuantity() {
26: return quantity;
27: }
28:
29: public long getTotal() {
30: return total;
31: }
32:
33: public void incrementQuantity() {
34: quantity++;
35: calculateTotal();
36: }
37:
38: public boolean isInStock() {
39: return inStock;
40: }
41:
42: public void setInStock(boolean isInStock) {
43: this .inStock = isInStock;
44: }
45:
46: public void setItem(Item anItem) {
47: this .item = anItem;
48: calculateTotal();
49: }
50:
51: public void setQuantity(int aQuantity) {
52: this.quantity = aQuantity;
53: calculateTotal();
54: }
55: }
|