-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCartItem.java
More file actions
46 lines (35 loc) · 870 Bytes
/
CartItem.java
File metadata and controls
46 lines (35 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package onlineshop.merchandise;
import onlineshop.Shop;
import org.springframework.beans.BeanUtils;
/**
* Represents an article/book in the shopping cart
*/
public class CartItem extends Book {
private int quantity = 0;
public CartItem() {
}
public CartItem(Book book) {
BeanUtils.copyProperties(book, this);
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public boolean getShowQuantity() {
return quantity > 1;
}
public void increaseQuantity() {
quantity++;
}
public void decreaseQuantity() {
quantity--;
}
public double getSubtotal() {
return quantity * price;
}
public String getTotalPriceFormatted() {
return Shop.df.format(getSubtotal());
}
}