Created
February 13, 2015 15:11
-
-
Save mosser/a5321c0d6bb25467fb3d to your computer and use it in GitHub Desktop.
the code that fulfills 100% of the expected value for the Carpaccio exercise,
This file contains hidden or 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
import scala.io.StdIn | |
object ElephantCarpaccio extends App { | |
val nbHats = StdIn.readLine("nbHats>").toInt | |
println(s"Selling $nbHats items") | |
val price = StdIn.readLine("price>").toFloat | |
println(s"Price per item is set to $$$price") | |
val withoutTaxes = nbHats * price | |
println(s"Raw price: $$$withoutTaxes") | |
val discount = withoutTaxes match { | |
case p if p < 1000 => 1.0 | |
case p if p < 5000 => 0.97 | |
case p if p < 7000 => 0.95 | |
case p if p < 10000 => 0.93 | |
case p if p < 50000 => 0.90 | |
case _ => 0.85 | |
} | |
val withDiscount = withoutTaxes * discount | |
if (discount < 1.0) | |
println(s"Discounted price: $$${withDiscount.}") | |
val code = StdIn.readLine("state>") | |
val taxes = Map("UT" -> 1.0685, "NV" -> 1.08, "TX" -> 1.0625, | |
"AL" -> 1.04, "CA" -> 1.0825) | |
val localTax = taxes.getOrElse(code, 1.0) | |
println(s"Taxes are set to $localTax") | |
val finalPrice = withDiscount * localTax | |
println(s"Final price: $$$finalPrice") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment