From 6a44b074f0169a1b0f9e92347af929c5e471746e Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Sat, 18 Apr 2015 13:44:44 +0200 Subject: Reorganised projects --- Week9 Webshop/src/com/camilstaps/shop/Order.java | 67 ++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 Week9 Webshop/src/com/camilstaps/shop/Order.java (limited to 'Week9 Webshop/src/com/camilstaps/shop/Order.java') diff --git a/Week9 Webshop/src/com/camilstaps/shop/Order.java b/Week9 Webshop/src/com/camilstaps/shop/Order.java new file mode 100644 index 0000000..2b0c5a7 --- /dev/null +++ b/Week9 Webshop/src/com/camilstaps/shop/Order.java @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2015 Camil Staps + * See the LICENSE file for copying permission. + */ + +package com.camilstaps.shop; + +import java.util.HashSet; +import java.util.Set; + +/** + * An order is a set of articles, purchased by a user + * @author Camil Staps, s4498062 + */ +public class Order extends DatabaseItem { + + private final Set
articles; + private final User user; + private boolean paid = false; + + /** + * This constructor takes the articles from the Cart of the User, and clears + * that Cart afterwards. + * @param user + */ + public Order(User user) { + this.user = user; + articles = new HashSet<>(); + for (Article a : user.getCart().getArticles()) { + articles.add(a); + } + user.getCart().getArticles().clear(); + } + + public User getUser() { + return user; + } + + public Set
getArticles() { + return articles; + } + + public void setPaid(boolean set) { + paid = set; + } + + /** + * See whether payment has been received for this article already + * @return + */ + public boolean isPaid() { + return paid; + } + + /** + * Get the total price of all articles + * @return + */ + public float getTotalAmount() { + float result = 0; + for (Article a : articles) { + result += a.getPrice(); + } + return result; + } + +} -- cgit v1.2.3