Converting minutes to hours in a time application

Report a typo

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?

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))
whenreturnfun
___

Create a free account to access the full topic