8.5

#### Lab 4: Working with Abstract Classes, Problem Solving

Exam 1 prep: Before beginning the lab problems, please do the Hourglass tutorial at https://hourglass.khoury.northeastern.edu/. This will allow you to become familiar with the tool we will use for Exam 1 on the 22nd. Please use Firefox for accessing Hourglass.

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.

Submission: Submit your solutions to Problem 1 in handins before leaving lab. This is due by the end of your lab and is graded on effort and good design.

### 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-designed 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 8568 with due date on the day 8582.

               +-------+
| IBook |
+-------+
/ \
---
|
---------------------------------------
|                  |                  |
+---------------+  +---------------+  +---------------+
| Book          |  | RefBook       |  | AudioBook     |
+---------------+  +---------------+  +---------------+
| String title  |  | String title  |  | String title  |
| String author |  | int dayTaken  |  | String author |
| int dayTaken  |  +---------------+  | int dayTaken  |
+---------------+                     +---------------+
• Design the interfaces and classes that represent the library borrowing system.

Define the abstract class ABook and lift those fields that can be lifted to this class.

• Design the method daysOverdue that consumes the number that represents today in the library date-recording system and produces the number of days this book is overdue. If the number is negative, the book can still be out for that many days.

• Design the method isOverdue that produces a boolean value that informs us whether the book is overdue on the given day.

• Design the method computeFine that computes the fine for this book, if the book is returned on the given day.

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.

• Design a method on a list of integers which produces the integer (or throws an exception if the list was empty) that appears in the longest consecutive sublist. For example, the list of 1,1,5,5,5,4,3,4,4,4 would produce 5 (note that ties are broken by the sublist that appears earlier in the list).