A library lends books, magazines and DVDs. Design the family so that nothing is written twice.
LibraryItem(title, year) (the parent):
describe() returns "<title> (<year>)", like "Dune (1965)".loan_days() returns 21.daily_fine() returns 0.25.late_fee(days_kept) returns the fine for keeping the item days_kept days. Days past loan_days() are overdue. The fee is overdue days × daily_fine(), rounded to 2 decimal places. If nothing is overdue, it's 0.Children (each lets the parent set up title and year):
| Class | Made with | describe() adds | loan_days() | daily_fine() |
|---|---|---|---|---|
Book | Book(title, year, author) | " by <author>" | same as parent | same as parent |
Magazine | Magazine(title, year, issue) | ", issue <issue>" | 7 | 0.1 |
DVD | DVD(title, year, minutes) | ", <minutes> min" | 3 | 1.0 |
describe() in each child adds its part after the parent's text. late_fee should only be written once, in the parent.
Finally, write fees_due(items, days_kept): the total late fee if every item in the list is kept for days_kept days, rounded to 2 decimal places. An empty list gives 0.