Skip to content

Instantly share code, notes, and snippets.

@modalsoul
Created March 2, 2014 09:17
Show Gist options
  • Select an option

  • Save modalsoul/9303992 to your computer and use it in GitHub Desktop.

Select an option

Save modalsoul/9303992 to your computer and use it in GitHub Desktop.
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