Spot the bug in the account balance

from Object-oriented programming
Kotlin 2.4.10 beginner 4 min 1 issue to find

The balance must never be negative. Find the object-boundary bug.

kotlin
class Wallet(initialCents: Int) {
    var balanceCents: Int = initialCents

    init {
        require(initialCents >= 0)
    }

    fun spend(cents: Int): Boolean {
        require(cents > 0)
        if (cents > balanceCents) return false
        balanceCents -= cents
        return true
    }
}

fun main() {
    val wallet = Wallet(500)
    wallet.balanceCents = -1
    println(wallet.balanceCents)
}
Open in playground
Report an error