On this page:
Problem 1: Books and abstraction
Abstraction
Problem 2:   Problem Solving Practice
8.5

Lab 4: Working with Abstract Classes, Problem Solving

Goals: The goals of this lab are to learn how to design and use abstract classes, and to solve problems with the use of accumulators.

Problem 1: Books and abstraction

Abstraction

Submission: You will submit your solution to this problem in handins. To earn full credit on this, your solution must be well-designd and a good attempt.

The following class diagram represents a library system that records the books that have been borrowed. There are three kinds of books: regular books, reference books, and audio books.

Reference books can be taken out for just two days, while other kinds of books may be borrowed for two weeks. The overdue fees are 10 cents per day for reference books and regular books, and 20 cents per day for audio books.

Audio books and regular books have both authors and titles; reference books only have titles.

The day when the book is taken out and the day due are counted as days since the library opened on New Year’s Day in 2001. So, for example, an audio book taken out recently would be recorded as taken out on the day 8502 with due date on the day 8516.

               +-------+
               | IBook |
               +-------+
                  / \
                  ---
                   |
       ---------------------------------------
       |                  |                  |
+---------------+  +---------------+  +---------------+
| Book          |  | RefBook       |  | AudioBook     |
+---------------+  +---------------+  +---------------+
| String title  |  | String title  |  | String title  |
| String author |  | int dayTaken  |  | String author |
| int dayTaken  |  +---------------+  | int dayTaken  |
+---------------+                     +---------------+

For all methods, think carefully whether they should be designed being implemented solely in the abstract class, implemented solely in the concrete classes, or implemented in the abstract class and then overridden in some of the concrete classes.

Problem 2: Problem Solving Practice

The rest of the lab will be dedicated to strengthening problem solving skills, in particular the use of accumulators. It will require you to create new classes as well as determine what helper methods would be appropriate.