package bhylu.lessons.k_hire_project class HireCounter(val capacity: Int) { init { require(capacity >= 0) } var hired = 0 private set val free: Int get() = capacity - hired fun hire(amount: Int): Boolean { if (amount <= 0 || amount > free) return false hired += amount return true } } fun main() { val desk = HireCounter(5) for (amount in listOf(2, 0, 4, 3)) { println("${desk.hire(amount)} ${desk.hired}") } println("free=${desk.free}") }