From 6dddd3bdcf20f974394e8b8c32e56dee65c1bc70 Mon Sep 17 00:00:00 2001 From: Alexis Drai Date: Fri, 7 Oct 2022 14:25:59 +0200 Subject: [PATCH] :necktie: Code the model --- .idea/workspace.xml | 32 +++++++++++++++++++++++++++----- src/data/Loadable.java | 7 +++++++ src/data/Stub.java | 34 ++++++++++++++++++++++++++++++++++ src/model/Garment.java | 38 ++++++++++++++++++++++++++++++++++++++ src/model/Perfume.java | 27 +++++++++++++++++++++++++++ src/model/Product.java | 30 ++++++++++++++++++++++++++++++ src/model/Shop.java | 22 ++++++++++++++++++++++ src/model/Size.java | 14 ++++++++++++++ 8 files changed, 199 insertions(+), 5 deletions(-) create mode 100644 src/data/Loadable.java create mode 100644 src/data/Stub.java create mode 100644 src/model/Garment.java create mode 100644 src/model/Perfume.java create mode 100644 src/model/Product.java create mode 100644 src/model/Shop.java create mode 100644 src/model/Size.java diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 42377b3..17080df 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,12 +4,15 @@ + + + \ No newline at end of file diff --git a/src/data/Loadable.java b/src/data/Loadable.java new file mode 100644 index 0000000..8dbe83a --- /dev/null +++ b/src/data/Loadable.java @@ -0,0 +1,7 @@ +package data; + +import model.Shop; + +interface Loadable { + Shop load(); +} diff --git a/src/data/Stub.java b/src/data/Stub.java new file mode 100644 index 0000000..c3ddc70 --- /dev/null +++ b/src/data/Stub.java @@ -0,0 +1,34 @@ +package data; + +import model.*; + +public class Stub implements Loadable { + + @Override + public Shop load() { + Shop shop = new Shop(); + + Garment p1 = new Garment("shirt", 15.9); + p1.addAllSizes(); + + Garment p2 = new Garment("sweater", 34.9); + p1.addSize(Size.valueOf("XXL")); + p1.addSize(Size.valueOf("XXS")); + p1.addSize(Size.valueOf("XS")); + + Perfume p3 = new Perfume("spiderman", 89.9); + p3.addSmell("woody"); + p3.addSmell("musky"); + + Perfume p4 = new Perfume("boring", 143.9); + p3.addSmell("flowery"); + p3.addSmell("acidic"); + + shop.addProduct(p1); + shop.addProduct(p2); + shop.addProduct(p3); + shop.addProduct(p4); + + return shop; + } +} diff --git a/src/model/Garment.java b/src/model/Garment.java new file mode 100644 index 0000000..a7d23d1 --- /dev/null +++ b/src/model/Garment.java @@ -0,0 +1,38 @@ +package model; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class Garment extends Product { + +// private List colors = new ArrayList<>(); + + /** + * if there are 3 shirts in M, the list will contain M, M, M + */ + private final List sizes = new ArrayList<>(); + + public Garment(String name, double price) { + super(name, price); + } + + public void addSize(Size size) { + sizes.add(size); + } + + public void addAllSizes() { + sizes.addAll(Arrays.asList(Size.values())); + } + + + public List getSizes() { + return Collections.unmodifiableList(sizes); + } + + public void removeSize(Size size) { + sizes.remove(size); + } +} + diff --git a/src/model/Perfume.java b/src/model/Perfume.java new file mode 100644 index 0000000..0759497 --- /dev/null +++ b/src/model/Perfume.java @@ -0,0 +1,27 @@ +package model; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class Perfume extends Product { + + private final List smells = new ArrayList<>(); + + public Perfume(String name, double price) { + super(name, price); + } + + public void addSmell(String smell) { + smells.add(smell); + } + + public List getSmells() { + return Collections.unmodifiableList(smells); + } + + public void removeSmell(String smell) { + smells.remove(smell); + } + +} diff --git a/src/model/Product.java b/src/model/Product.java new file mode 100644 index 0000000..c3718a3 --- /dev/null +++ b/src/model/Product.java @@ -0,0 +1,30 @@ +package model; + +public abstract class Product { + + private String name; + + private double price; + + public Product(String name, double price) { + this.name = name; + this.price = price; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public double getPrice() { + return price; + } + + public void setPrice(float price) { + this.price = price; + } + +} diff --git a/src/model/Shop.java b/src/model/Shop.java new file mode 100644 index 0000000..7563b87 --- /dev/null +++ b/src/model/Shop.java @@ -0,0 +1,22 @@ +package model; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class Shop { + + private final List products = new ArrayList<>(); + + public void addProduct(Product product) { + products.add(product); + } + + public List getProducts() { + return Collections.unmodifiableList(products); + } + + public void removeProduct(Product product) { + products.remove(product); + } +} diff --git a/src/model/Size.java b/src/model/Size.java new file mode 100644 index 0000000..3877c4c --- /dev/null +++ b/src/model/Size.java @@ -0,0 +1,14 @@ +package model; + +/** + * XXS to XXL + */ +public enum Size { + XXS, + XS, + S, + M, + L, + XL, + XXL +}