Build a study-budget calculator
Combine variables, parsing, arithmetic, and formatted output in a small console program. Accept a daily study budget and report complete 25-minute blocks plus leftover minutes. Keep the calculation independent from console input so it can be checked repeatedly.
fun summary(minutes: Int): String {
require(minutes >= 0) { "Minutes cannot be negative" }
val blocks = minutes / 25
val remainder = minutes % 25
return "$blocks blocks, $remainder minutes left"
}
fun main() {
check(summary(60) == "2 blocks, 10 minutes left")
check(summary(0) == "0 blocks, 0 minutes left")
println(summary(60))
}
The remainder operator gives the unused minutes. A precondition protects the calculation from invalid callers; the input layer should show a friendly message before calling it with invalid data.
Your implementation
Read input using readlnOrNull(), normalize surrounding whitespace, and parse with toIntOrNull(). Add a course name to the output. Do not convert invalid input to zero, since that hides the difference between a valid empty budget and a typing mistake.
Acceptance checks: 25 gives one block, 24 gives zero blocks and 24 minutes, 50 gives two blocks, and negative or nonnumeric input is rejected. Explain how integer division and remainder work together.