Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A) Write an Author class, that holds the name of the author. Write an appropriate constructor, a getter and setter plus a toString() for the

A) Write an Author class, that holds the name of the author. Write an appropriate constructor, a getter and setter plus a toString() for the Author. Write a bit of test code to make sure your Author is working -- create an Author, and invoke the toString, as part of the test.

B) Write a Book class, where a book is represented by a title and a year of publication. You should write a constructor that takes both a title and a year and initializes the data fields appropriately. Also write appropriate getters for both fields, and a toString that returns a reasonably formatted representation of the Book.

C) Add an author field to your Book class, with an appropriate getter and setter. The setAuthor and getAuthor methods should take/return an object of type Author, not a String representing the name of the Author.

Modify your Book constructor so that it requires an Author. Be sure that it uses the setAuthor() method you just wrote.

D) Add an ArrayList of Book to your Author class which will hold all the books written by this author. Add a method named addBook() to add a book to this list of books.

In your Book class, change your setAuthor() method so it also calls the addBook() method on the author to add the Book to the list of books by the given Author.

E) Add a displayWorks() method to Author which will print the Author's name and then all books written by the author, one per line. Format this list nicely, by indenting slightly.

F) Define a Series class which would keep track of an series of related books -- like the seven Harry Potter books. This class should store a series name and an ArrayList of Books. Be sure to write a constructor, getters and setters for the series name, and an addBook method to add a new book to a series. Include a getAuthors method to construct and return an ArrayList of all Authors who contributed to the series. Use the contains method on ArrayList to ensure that you don't include an author more than once. You'll also want a getBooks method to get all the books in the series.

G) Extend your Book class to include an optional series field. This field would be set with a setSeries method, which would also add the book to the list of books on the series.

H) Define another class named ReadingList. A reading list consists of a name, and a list of books to read. Methods to write:

-- constructor that takes a name for the reading list. Be sure to create an empty list for your books, too

-- getName -- returns the name of the readingList

-- add(Book b) -- adds a single book to the reading list

-- add(Series s) -- adds all the books in a series to the reading list

-- displayItems -- display the name of the list, plus all the items in the reading list

To make this work, you'll also want to add getBooks to your Series class that add(Series s) can call to get all the books in your series. getBooks should return a list of Books.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

3. Define the roles individuals play in a group

Answered: 1 week ago