6.6. Exercises
Given the following abstraction:
A book is a collection of chapters, which are each collections of pages.
sketch out the code for the Book, Chapter, and Page classes:
Invent whatever fields you think would be relevant, taking advantage of collections as fields where appropriate.
Include methods on the Chapter class for adding pages and for determining how many pages a chapter contains.
Include methods on the Book class for adding chapters, for determining how many chapters the book contains, for determining how many pages the book contains (hint: use delegation!), and for printing out a book's table of contents.
What general type(s) of collection(s)—ordered list, sorted ordered list, set, dictionary—might you use to represent each of ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access