Menu
Coddy logo textTech

Returning Books

Part of the Object Oriented Programming section of Coddy's Kotlin journey. Lesson 52 of 57.

challenge icon

Challenge

Easy

Add the RETURN command. Your code from the previous step is already in Library.kt; keep every command working exactly as before.

  • RETURN <name> <id>: reply no member bo or no book 9 as for borrowing; if the member does not hold that book reply ada does not have Dune; otherwise remove the loan from the member, make the book available and reply ada returned Dune.

The supplied code passes every input line to library.handle(line) and prints each returned reply on its own line. Member names are single lower-case words, book ids are whole numbers, and the input holds only the commands described so far. Any other command replies unknown command.

Your code goes in Book.kt, Member.kt and Library.kt. Main.kt holds the supplied input/output code and cannot be edited.

Try it yourself

fun main() {
    // Supplied input/output code: keep it as it is
    val input = generateSequence(::readLine).toList()
    val library = Library()
    for (line in input) {
        for (reply in library.handle(line)) println(reply)
    }
}

All lessons in Object Oriented Programming

Practice on your own: Kotlin playground