diff --git a/src/main/java/io/shodo/BasketInformations.java b/src/main/java/io/shodo/BasketInformations.java new file mode 100644 index 0000000..8e3d550 --- /dev/null +++ b/src/main/java/io/shodo/BasketInformations.java @@ -0,0 +1,56 @@ +package io.shodo; + +import java.util.HashMap; + +/** + * Created by thomas on 02/12/2019. + * This class is a basket + */ +public class BasketInformations { + + // The product of the basket + static HashMap map = new HashMap(); + + // The fact that the basket has promo code + private static boolean codeDePromotion = false; + + public void addProductToBasket(String product, Integer price, boolean isPromoCode) { + if (isPromoCode) { + codeDePromotion = true; + } else { + map.put(product, price); + } + } + + public Long getBasketPrice(boolean inCents) { + Integer v = 0; + for (String s : map.keySet()) { + v += map.get(s); + } + if (codeDePromotion) { + v -= 100; + } + return inCents ? v * 100 : Long.valueOf(v); + } + + public void resetBasket() { + buyBasket(); + codeDePromotion = false; + } + + public void buyBasket() { + map.clear(); + } + + public boolean isBasketContains(String produit) { + boolean found = false; + for (String s : map.keySet()) { + if (s == produit) found = true; + } + return found; + } + + public void mixWithBasket(BasketInformations b) { + map.putAll(b.map); + } +}