Skip to content

Instantly share code, notes, and snippets.

@tasdemirbahadir
Last active October 9, 2018 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tasdemirbahadir/7a3524bd68a5ebc2e1602e779197a319 to your computer and use it in GitHub Desktop.
Save tasdemirbahadir/7a3524bd68a5ebc2e1602e779197a319 to your computer and use it in GitHub Desktop.
My 99 Bottles of Beer Lyrics in Kotlin PL. Aided with the source: http://bit.ly/2Nvjh9f
fun main(args: Array<String>) {
printSongLyrics(99)
}
fun printSongLyrics(bottlesSize: Int) {
if (bottlesSize < 0) {
println("Do not enter negative values!")
return
}
println("Lyrics of the song $bottlesSize Bottles of Beer\n")
for (bottleIndex in bottlesSize downTo 0)
printLyricsPart(bottleIndex, bottlesSize)
}
fun printLyricsPart(bottlesSize: Int, bottlesTotalSize: Int) {
val firstLine = "${getBottleAmountText(bottlesSize)} on the wall, ${getBottleAmountText(bottlesSize)}.\n"
if (bottlesSize >= 1) {
println(firstLine +
"Take one down and pass it around, ${getBottleAmountText(bottlesSize - 1)} on the wall.\n")
} else {
println(firstLine +
"Go to the store and buy some more, $bottlesTotalSize bottles of beer on the wall.")
}
}
fun getBottleAmountText(bottlesSize: Int) =
when (bottlesSize) {
1 -> "1 bottle"
0 -> "no more bottles"
else -> "$bottlesSize bottles"
} + " of beer"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment