Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object Birthday extends App {
- val recipe = List("Flour", "Sugar", "Baking Powder", "Eggs", "Vanilla")
- val dryStuff = recipe.slice(0, 3)
- val wetStuff = recipe.slice(3, 5)
- class Cake() {
- var mixingBowl = ""
- def mix(stuffToMix: List[String]) = {
- val mixTwo = (one: String, two: String) => (one + " and " + two)
- if (!mixingBowl.isEmpty()) mixingBowl += " and "
- mixingBowl += "(" + stuffToMix.reduceLeft(mixTwo) + ")"
- println("Mixing bowl contains: " + mixingBowl)
- }
- def bake() {
- var ingredientsPresent = true
- for (ing <- recipe) {
- if (!mixingBowl.contains(ing)) {
- ingredientsPresent = false
- }
- }
- if (ingredientsPresent) {
- println("Ingredients correct!")
- Thread.sleep(500)
- print("Baking")
- for (i <- (0 to 4)) {
- Thread.sleep(900)
- print(".")
- }
- println("Cake complete! Happy Birthday!")
- } else {
- println("Required ingredients not detected")
- }
- }
- }
- val bDayCake = new Cake
- println("Recipe: ")
- recipe.foreach(str => println("\t" + str))
- Thread.sleep(1000)
- bDayCake.mix(dryStuff)
- Thread.sleep(1000)
- bDayCake.mix(wetStuff)
- Thread.sleep(1000)
- bDayCake.bake()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement