Created
March 2, 2014 09:17
-
-
Save modalsoul/9303992 to your computer and use it in GitHub Desktop.
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
| class Lylic(num:Int) { | |
| val currentPlural = plural(num) | |
| val nextPlural = plural(num-1) | |
| def plural(x:Int) = { | |
| x match { | |
| case 0 => "No more bottles" | |
| case 1 => "1 bottle" | |
| case _ => x + " bottles" | |
| } | |
| } | |
| def over = { | |
| currentPlural + " of beer on the wall, " + currentPlural.capitalize + " of beer." | |
| } | |
| def under = { | |
| if(num == 0) "Go to the store and buy some more, 99 bottles of beer on the wall." | |
| else "Take one down and pass it around, " + nextPlural.capitalize + " of beer on the wall." | |
| } | |
| val get = "\n" + over + "\n" + under | |
| } | |
| (0 to 4).reverse.foreach { num => | |
| println(new Lylic(num).get) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment