blob: fd78bd3b20f765f2de2595127fef46a80c468420 (
plain) (
blame)
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
47
48
49
50
51
|
/*
* Copyright (c) 2015 Camil Staps
*/
package com.camilstaps.webshop;
import com.camilstaps.webshop.article.Article;
import com.camilstaps.webshop.payment.IDeal;
import com.camilstaps.webshop.payment.PaymentMethod;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author camilstaps
*/
public class Cart extends ArrayList<Article> {
private PaymentMethod paymentMethod;
public double getSubtotal() {
double total = 0;
for (Article a : this) {
total += a.getPrice();
}
return total;
}
public double getShippingCosts() {
List<Double> seenCosts = new ArrayList<>();
double total = 0;
for (Article a : this) {
if (!seenCosts.contains(a.getShippingCosts())) {
seenCosts.add(a.getShippingCosts());
total += a.getShippingCosts();
}
}
return total;
}
public double getTotal() {
return getSubtotal() + getShippingCosts();
}
public boolean pay() {
if (paymentMethod == null) {
paymentMethod = new IDeal("ASN", "740249240", "2940");
}
return paymentMethod.pay(getTotal());
}
}
|