Borrowing Books
Part of the Object Oriented Programming section of Coddy's R journey. Lesson 51 of 57.
Challenge
EasyAdd the BORROW command through the method borrow(name, id). Keep every command from the previous steps working exactly as before.
BORROW <name> <id>: check in this order and reply with the first problem:no member bo,no book 9,Dune is not available,ada has reached the limit(members may hold at mostlimitbooks, 2). Otherwise record the loan on both the book (borrower) and the member (borrowed) and replyada borrowed 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
1S3 Basics
Working With FilesLists With a ClassConstructor FunctionsPrint and Format MethodsValidators and HelpersRecap - Temperatures4Encapsulation in R
Closures as ObjectsEnvironments as ObjectsAccessor FunctionsGuarding StateRecap - Parking Meter2S3 Generics and Methods
Generics and UseMethodDefault MethodsMethods for Base GenericsNextMethod BasicsRecap - Shape Areas8Reference Classes
Defining Reference ClassesMethods and Field UpdatesCopy SemanticsInheritance and callSuperRecap - Task Queue11Project: Library Management
Books and MembersBorrowing BooksPractice on your own: Online R compiler