Last active
October 9, 2018 13:40
-
-
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
This file contains 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
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