A loan desk
The workshop on Birch Lane lends its tools to its members: a drill for a weekend, a ladder for a week. In this project you build the program that runs its loan desk. When it's finished, it loads the shelf from a file when it starts, takes commands at the desk, and saves the shelf again when the desk closes.
Days are plain day numbers (day 1, day 2, ...), so no calendar is needed. A loan lasts 7 days: a tool lent on day 14 is due back on day 21.
The shelf is kept in shelf.csv, one line per tool, member and loan, with the parts separated by commas. loan,T3,M1,11 means that the tool T3 is out with the member whose card is M1, due back on day 11:
tool,T1,Cordless drill
tool,T2,Hand saw
tool,T3,Ladder
member,M1,Noor
member,M2,Ilse
loan,T3,M1,11
A day at the desk. The person at the desk types these commands:
day 14
loans
lend T1 M2
lend T3 M2
return T3
late
quit
and the program answers:
It's day 14
T3 Ladder: Noor (M1), due day 11
Lent: T1 Cordless drill: Ilse (M2), due day 21
Sorry: T3 Ladder is out, due back on day 11
T3 Ladder is back, 3 days late
Nothing is late
Saved shelf.csv
The ladder can't be lent to Ilse while Noor still has it, so the desk refuses with a message instead of crashing. After quit, shelf.csv has the loan of the drill instead of the ladder's.
The finished program has these classes (and an exception class of its own, LoanException):
The diagram as text
- TextUi, a class
- private field
today: int - public method
start(): void
- private field
- ToolShelf, a class
- public method
lend(code: String, card: String, today: int): Loan - public method
giveBack(code: String, today: int): int - public method
save(fileName: String): void - public method
load(fileName: String): void - more members, not shown
- public method
- Loan, a class
- private field
dueDay: int - public method
isLate(today: int): boolean
- private field
- Tool, a class
- private field
code: String - private field
name: String
- private field
- Member, a class
- private field
card: String - private field
name: String
- private field
Connections:
- Each TextUi has one ToolShelf object.
- Each ToolShelf has any number of Tool objects.
- Each ToolShelf has any number of Member objects.
- Each ToolShelf has any number of Loan objects.
- Each Loan has one Tool object.
- Each Loan has one Member object.
What you need
Everything up to the end of part 11: classes and objects (modules 17 to 19), reading files (module 20), a text UI (module 25), hash maps (module 31), interfaces and Comparable (modules 35 and 38), exceptions (module 42) and writing files (module 43).
The milestones
- Tools and members, in two hash maps, printed in order.
- Loans with due days, and which ones are late.
- Refusals: an exception class of your own for a loan that can't happen.
- Saving the shelf to a CSV file.
- Loading it back, with a clear message for a damaged line.
- The desk: a text UI over the shelf.
The checks of the first five milestones call your classes' methods directly; main becomes the desk only in the last one.
Milestones
- Tools and members
- Loans and due days
- Refusals
- Saving to a CSV file
- Loading, and damaged lines
- The desk