Menu
Coddy logo textTech

Returning Books

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

challenge icon

Challenge

Easy

Add the RETURN command through the method return_book(name, id). Keep every command from the previous steps 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 id from the member's loans, make the book available (borrower becomes character(0)) and reply ada returned Dune.

The supplied code sends every input line to lib$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.R, Member.R and Library.R. main.R holds the supplied input/output code and cannot be edited.

Try it yourself

source("Book.R")
source("Member.R")
source("Library.R")

# Supplied input/output code: keep it as it is
input <- suppressWarnings(readLines(file("stdin")))
lib <- Library$new()
for (line in input) {
  for (reply in lib$handle(line)) cat(reply, "\n", sep = "")
}

All lessons in Object Oriented Programming

Practice on your own: Online R compiler