aboutsummaryrefslogtreecommitdiff
path: root/Week16 Webshop/src/com/camilstaps/webshop/Cart.java
diff options
context:
space:
mode:
Diffstat (limited to 'Week16 Webshop/src/com/camilstaps/webshop/Cart.java')
-rw-r--r--Week16 Webshop/src/com/camilstaps/webshop/Cart.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/Week16 Webshop/src/com/camilstaps/webshop/Cart.java b/Week16 Webshop/src/com/camilstaps/webshop/Cart.java
new file mode 100644
index 0000000..fd78bd3
--- /dev/null
+++ b/Week16 Webshop/src/com/camilstaps/webshop/Cart.java
@@ -0,0 +1,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());
+ }
+
+}