DEV Community

Discussion on: Daily Challenge #56 - Coffee Shop

Collapse
 
lprakashv profile image
Lalit Vatsal • Edited

Scala:

object CoffeeShop {
    private lazy val coffees = Map(
        2.2 -> "Americano",
        2.3 -> "Flat white",
        2.4 -> "Latte",
        3.5 -> "Filter"
    )

    //desired method
    def makeCoffee(change: Double): String = {
        coffees.get(change).fold("Sorry, exact change only, try again tomorrow!") {coffee => 
            s"Here is your $coffee, have a nice day!"
        }
    }
}