diff --git a/scala/src/BasketInformations.scala b/scala/src/BasketInformations.scala index 14bc119..3d5ea52 100644 --- a/scala/src/BasketInformations.scala +++ b/scala/src/BasketInformations.scala @@ -4,8 +4,15 @@ class BasketInformations { // The product of the basket val map: HashMap[String, Int] = HashMap() - def addProductToBasket(product: String, price: Int): Unit = { - map += (product -> price) + // The fact that the basket has promo code + private var codeDePromotion: Boolean = false + + def addProductToBasket(product: String, price: Int, isPromoCode: Boolean): Unit = { + if (isPromoCode) { + codeDePromotion = true + } else { + map += (product -> price) + } } def getBasketPrice(inCents: Boolean): Long = { @@ -13,6 +20,9 @@ class BasketInformations { for (s <- map.values) { v += s } + if (codeDePromotion) { + v -= 100 + } if (inCents) { v * 100 } else { @@ -22,6 +32,7 @@ class BasketInformations { def resetBasket(): Unit = { buyBasket() + codeDePromotion = false } def buyBasket(): Unit = {