Rolling die using classes - Kotlin
Thu Nov 21 2024 02:36:47 GMT+0000 (Coordinated Universal Time)
Saved by
@signup1
// Die.kt
class Die() {
fun roll(): Int {
return (1..6).random()
}
}
// Main.kt
fun main() {
println("Welcome to the Die Roller Application!")
val die = Die()
do {
println("Rolling the die...")
val result = die.roll()
println("You rolled a $result!")
println("Do you want to roll again? (yes/no)")
val input = readLine()?.trim()?.lowercase()
} while (input == "yes")
println("Thanks for using the Die Roller Application!")
}
content_copyCOPY
Comments