diff options
10 files changed, 238 insertions, 0 deletions
| diff --git a/Week16 Webshop/Assignment (in Dutch).pdf b/Week16 Webshop/Assignment (in Dutch).pdfBinary files differ new file mode 100644 index 0000000..d7d8c65 --- /dev/null +++ b/Week16 Webshop/Assignment (in Dutch).pdf 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()); +    } +     +} diff --git a/Week16 Webshop/src/com/camilstaps/webshop/article/Article.java b/Week16 Webshop/src/com/camilstaps/webshop/article/Article.java new file mode 100644 index 0000000..c0e53e5 --- /dev/null +++ b/Week16 Webshop/src/com/camilstaps/webshop/article/Article.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2015 Camil Staps + */ +package com.camilstaps.webshop.article; + +/** + * + * @author camilstaps + */ +public abstract class Article { +     +    protected final String description; +    protected final double price; +     +    public Article(String description, double price) { +        this.description = description; +        this.price = price; +    } +     +    public String getDescription() { +        return description; +    } +     +    public double getPrice() { +        return price; +    } +     +    public abstract double getShippingCosts(); +     +} diff --git a/Week16 Webshop/src/com/camilstaps/webshop/article/WashingMachine.java b/Week16 Webshop/src/com/camilstaps/webshop/article/WashingMachine.java new file mode 100644 index 0000000..37325f5 --- /dev/null +++ b/Week16 Webshop/src/com/camilstaps/webshop/article/WashingMachine.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2015 Camil Staps + */ +package com.camilstaps.webshop.article; + +/** + * + * @author camilstaps + */ +public class WashingMachine extends Article { + +    public WashingMachine() { +        super("Washing machine", 499); +    } + +    @Override +    public double getShippingCosts() { +        return 30; +    } +     +} diff --git a/Week16 Webshop/src/com/camilstaps/webshop/article/WaterMelon.java b/Week16 Webshop/src/com/camilstaps/webshop/article/WaterMelon.java new file mode 100644 index 0000000..0cdf1d4 --- /dev/null +++ b/Week16 Webshop/src/com/camilstaps/webshop/article/WaterMelon.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2015 Camil Staps + */ +package com.camilstaps.webshop.article; + +/** + * + * @author camilstaps + */ +public class WaterMelon extends Article { + +    public WaterMelon() { +        super("Watermelon", 4.5); +    } + +    @Override +    public double getShippingCosts() { +        return 6.75; +    } +     +} diff --git a/Week16 Webshop/src/com/camilstaps/webshop/article/WineGlass.java b/Week16 Webshop/src/com/camilstaps/webshop/article/WineGlass.java new file mode 100644 index 0000000..81e38e5 --- /dev/null +++ b/Week16 Webshop/src/com/camilstaps/webshop/article/WineGlass.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2015 Camil Staps + */ +package com.camilstaps.webshop.article; + +/** + * + * @author camilstaps + */ +public class WineGlass extends Article { + +    public WineGlass() { +        super("Wine glass", 8.5); +    } + +    @Override +    public double getShippingCosts() { +        return 6.75; +    } +     +} diff --git a/Week16 Webshop/src/com/camilstaps/webshop/payment/CreditCard.java b/Week16 Webshop/src/com/camilstaps/webshop/payment/CreditCard.java new file mode 100644 index 0000000..4ce6b31 --- /dev/null +++ b/Week16 Webshop/src/com/camilstaps/webshop/payment/CreditCard.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2015 Camil Staps + */ +package com.camilstaps.webshop.payment; + +import java.util.Date; + +/** + * + * @author camilstaps + */ +public class CreditCard implements PaymentMethod { +     +    private final String cardNr, holder; +    private final Date expiryDate; +     +    public CreditCard(String cardNr, String holder, Date expiryDate) { +        this.cardNr = cardNr; +        this.holder = holder; +        this.expiryDate = expiryDate; +    } + +    @Override +    public boolean pay(double amount) { +        System.out.println("€" + amount + " paid with credit card:\n" + holder + " with " + cardNr + " (" + expiryDate + ")"); +        return true; +    } +     +} diff --git a/Week16 Webshop/src/com/camilstaps/webshop/payment/IDeal.java b/Week16 Webshop/src/com/camilstaps/webshop/payment/IDeal.java new file mode 100644 index 0000000..0ed9454 --- /dev/null +++ b/Week16 Webshop/src/com/camilstaps/webshop/payment/IDeal.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2015 Camil Staps + */ +package com.camilstaps.webshop.payment; + +/** + * + * @author camilstaps + */ +public class IDeal implements PaymentMethod { +     +    private final String bank, accountNr, pincode; +     +    public IDeal(String bank, String accountNr, String pincode) { +        this.bank = bank; +        this.accountNr = accountNr; +        this.pincode = pincode; +    } + +    @Override +    public boolean pay(double amount) { +        System.out.println("€" + amount + " paid with iDeal: \n" + bank + " : " + accountNr + " (" + pincode + ")"); +        return true; +    } +     +} diff --git a/Week16 Webshop/src/com/camilstaps/webshop/payment/PayPal.java b/Week16 Webshop/src/com/camilstaps/webshop/payment/PayPal.java new file mode 100644 index 0000000..c893da1 --- /dev/null +++ b/Week16 Webshop/src/com/camilstaps/webshop/payment/PayPal.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2015 Camil Staps + */ +package com.camilstaps.webshop.payment; + +/** + * + * @author camilstaps + */ +public class PayPal implements PaymentMethod { +     +    private final String email, pass; +     +    public PayPal(String email, String pass) { +        this.email = email; +        this.pass = pass; +    } + +    @Override +    public boolean pay(double amount) { +        System.out.println("€" + amount + " paid with PayPal:\n" + email + " (" + pass + ")"); +        return true; +    } +     +} diff --git a/Week16 Webshop/src/com/camilstaps/webshop/payment/PaymentMethod.java b/Week16 Webshop/src/com/camilstaps/webshop/payment/PaymentMethod.java new file mode 100644 index 0000000..966fcf2 --- /dev/null +++ b/Week16 Webshop/src/com/camilstaps/webshop/payment/PaymentMethod.java @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2015 Camil Staps + */ +package com.camilstaps.webshop.payment; + +/** + * + * @author camilstaps + */ +public interface PaymentMethod { +     +    boolean pay(double amount); +     +} | 
