Last active
February 10, 2021 15:55
-
-
Save mgryszko/176149b1eb3ecc7ef08a313ba00c937d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Pricing(val quantity: Int, val unitPrice: UnitPrice, val tierPrice: TierPrice) | |
case class UnitPrice(val price: BigDecimal) | |
case class TierPrice(val price: BigDecimal, val quantity: Int) | |
def total(croissants: Pricing, baguettes: Pricing): BigDecimal = { | |
val croissantTotal = total(croissants) | |
val baguetteTotal = total(baguettes) | |
croissantTotal + baguetteTotal | |
} | |
private def total(pricing: Pricing): BigDecimal = { | |
val tiers = pricing.quantity / pricing.tierPrice.quantity | |
val regularPricedArticles = pricing.quantity % pricing.tierPrice.quantity | |
tiers * pricing.tierPrice.price + regularPricedArticles * pricing.unitPrice.price | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment