Practice Time. Fish Food


Practice Time

Create a program with a function that gets a random day and another function that calculates the food for the fish.

 


import java.util.Random

fun main(args: Array<String>) {
println("Hello, Kotlin")
feedFish()
}

fun feedFish() {
val day = randomDay()
val food = fishFood(day)
println("Today is $day and the fish eat $food")
}

fun randomDay(): String {
val week = listOf<String>("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
return week[Random().nextInt(7)]
}

fun fishFood(day: String): String{
var food = "fasting" // Default Food for the fish

return when(day){
"Monday" -> "flakes"
"Wednesday" -> "redworms"
"Thursday" -> "mosquitoes"
"Sunday" -> "plankton"
else -> "fasting"
}
}

Comments

Popular posts from this blog