On this page:
Problem 1: Books and abstraction
5.1 Abstract Classes
5.2 Problem Solving Practice
8.5

Lab 5: Working with Abstract Classes, Problem Solving

Related files:
  SimpleBall.java  

Submission: Submit the Lab 5 assignment in handins. The questions you will need to answer are in the assignment. This is an individual submission.

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

5.1 Abstract Classes

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 8159 with due date on the day 8173.

               +-------+
               | 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.

5.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.