Exercise of the day

 

Practice Time

Create a program with a function that returns a fortune cookie message that you can print.

/** File:           Main.kt
* Description: Create a program with a function that returns a fortune
* cookie message that you can print.
* Programmer: Nolverto Urias Obesoo
* Creation Date: 06/13/2023
*/

fun main(args: Array<String>) {
// Use a for loop to run the program 10 times
for (iteration in 0..9){
println("Your fortune is: ${getFortuneCookie()}\n")
}
}

fun getFortuneCookie(): String{
val fortuneList = listOf(
"You will have a great day!",
"Things will go well for you today.",
"Enjoy a wonderful day of success.",
"Be humble and all will turn out well.",
"Today is a good day for exercising restraint.",
"Take it easy and enjoy life!",
"Treasure your friends because they are your greatest fortune.")

print("Enter your birthday: ")

// Use readLine() to read a line of input (completed with Enter) as a String.
val birthday = readLine()!!

// You can use toIntOrNull() to convert a number as a String to an Integer numeric.
// If the user enters "", toIntOrNull returns null.
// The next line gets the indexFortune calculating the reminder beteen the birthday and size of fortuneList
var indexFortune: Int? = birthday.toIntOrNull()?.mod(fortuneList.size)

return fortuneList[indexFortune!!]
}




Comments

Popular posts from this blog