Suppose you are developing a time conversion application in Kotlin. Users will input time in minutes and your application needs to output the time in terms of hours and minutes if the input time is more than 60 minutes, otherwise just output the minutes. You realize the task can be broken down into smaller ones, one function to convert the minutes to hours and another to decide which format to display the time in. But you forgot to fill some parts of your code. Can you help to fill the blanks in code so the application works as expected?
Functional decomposition
Converting minutes to hours in a time application
Report a typo
Fill in the gaps with the relevant elements
convertToHour(minutes: Int): String {
val hours = minutes / 60
val remainingMinutes = minutes % 60
"$hours hour(s) and $remainingMinutes minute(s)"
}
fun timeFormat(minutes: Int): String {
return {
minutes < 60 -> "$minutes minute(s)"
else -> convertToHour(minutes)
}
}
println(timeFormat(40))
println(timeFormat(75)) ___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.