aboutsummaryrefslogtreecommitdiff
path: root/Week9/src/com/camilstaps/shop/Order.java
diff options
context:
space:
mode:
authorCamil Staps2015-04-18 00:26:48 +0200
committerCamil Staps2015-04-18 00:26:48 +0200
commit6dd7405206b2babfe491b59250f4d1d7f78e654b (patch)
treea5e53ec980a4cbdce038dd0beb3c8fe71fa0e80c /Week9/src/com/camilstaps/shop/Order.java
parentAdded tarball w8 (diff)
Week9
Diffstat (limited to 'Week9/src/com/camilstaps/shop/Order.java')
-rw-r--r--Week9/src/com/camilstaps/shop/Order.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/Week9/src/com/camilstaps/shop/Order.java b/Week9/src/com/camilstaps/shop/Order.java
new file mode 100644
index 0000000..92d04d7
--- /dev/null
+++ b/Week9/src/com/camilstaps/shop/Order.java
@@ -0,0 +1,67 @@
+/**
+ * Copyright (c) 2015 Camil Staps <info@camilstaps.nl>
+ * 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<Article> 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().clear();
+ }
+
+ public User getUser() {
+ return user;
+ }
+
+ public Set<Article> 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;
+ }
+
+}