Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions scala/src/BasketInformations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,25 @@ 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 = {
var v: Int = 0
for (s <- map.values) {
v += s
}
if (codeDePromotion) {
v -= 100
}
if (inCents) {
v * 100
} else {
Expand All @@ -22,6 +32,7 @@ class BasketInformations {

def resetBasket(): Unit = {
buyBasket()
codeDePromotion = false
}

def buyBasket(): Unit = {
Expand Down