A library loan desk
The neighborhood library on Elm Street has a few shelves of books and a loan desk run by volunteers. In this project you write the program for that desk. Days are plain day numbers (day 1, day 2, and so on), so no calendar is needed. A loan lasts 14 days: a book lent on day 3 is due back on day 17.
When it's finished, the program reads the library's books and members from the file library.txt, one per line:
book;B1;Emma;Jane Austen
book;B2;Dracula;Bram Stoker
book;B3;Persuasion;Jane Austen
member;M1;Ada
member;M2;Ben
Then the volunteer at the desk types commands. These ones
books
lend B1 M1
lend B1 M2
day 20
late
return B1
lend B3 M2
member M2
search austen
dance
quit
get these answers:
Day 1 at the desk.
> books
B1 Emma by Jane Austen
B2 Dracula by Bram Stoker
B3 Persuasion by Jane Austen
> lend B1 M1
Lent: Emma (B1) to Ada (M1), due day 15
> lend B1 M2
Emma is out until day 15.
> day 20
It is day 20.
> late
Emma (B1) to Ada (M1), due day 15, 5 days late
> return B1
Emma is back, 5 days late.
> lend B3 M2
Lent: Persuasion (B3) to Ben (M2), due day 34
> member M2
Ben (M2) has 1 book:
Persuasion (B3) to Ben (M2), due day 34
> search austen
B1 Emma by Jane Austen
B3 Persuasion by Jane Austen
> dance
I don't know that command.
> quit
The desk is closed.
Ben can't borrow Emma while Ada has it, so the desk says so instead of lending one book twice.
The classes
The program has four classes, and much of the work is in how their objects point to each other:
- A
Bookhas a code, a title and an author, and its current loan:Nonewhile it's on the shelf. - A
Memberhas a library card (the card's code, such asM1), a name, and a list of their loans. - A
Loanhas a book, a member and the day the book is due. Its book and its member are objects, not codes. - The
Librarykeeps lists of all its books, members and loans, and does the lending.
What you need
Everything up to module 38: reading a file (module 23), try and except (module 25), and above all classes: attributes and the constructor __init__ (module 34), methods (module 35), __str__ (module 36), objects in lists and as arguments, and is (module 37), and objects as attributes of other objects, and None (module 38).
How you build it
- Books and members: the first classes, and a library that lists them.
- Finding things: a book by its code, a member by their card, and books by a word.
- Loans: a class for a loan, which knows its book and its member.
- Returns and late books: give a book back, and find what's late.
- A member's books: each member's own loans, and a limit of 3 books.
- The desk: read the library from a file and take commands.
The checks of the first five milestones call your classes' methods directly, as the lessons' checks do. The desk itself comes last.
Milestones
- Books and members
- Finding things
- Loans
- Returns and late books
- A member's books
- The desk