Question: Question 1 We are writing a software for a library which lends out books, DVDs and CDs. We are going to develop the system so

Question 1

We are writing a software for a library which lends out books, DVDs and CDs.

We are going to develop the system so that the details that are displayed depend on the type of item. If it is a book, author and title will be displayed. For a DVD, the title (film name), certificate, and lead actor are displayed. For a CD, title and artist are displayed. Book, CD and DVD are classes which inherit from LibraryItem.

Your Tasks

1. Create a LibraryItem class so that it only contains a title attribute, representing the LibraryItem's title. It should also have a getDescription() method. This should just return the title. Give it a constructor which initialises the title.

2. Inherit Book, DVD and CD from LibraryItem. Each subclass should have additional attributes representing the specific data associated with that subclass: author for Book; certificate and lead actor for DVD; and artist for CD. Also give each class a series of "getter" (accessor) methods to return each attribute, and give each class a suitable constructor.

3.Give each class a getDescription() method of its own. This should return the full details as a string, e.g. a string containing film name, certificate and lead actor for the DVD.

4.Test out your system with a main() and write up your inheritance hierarchy, clearly explaining all aspects of your code relating to inheritance.

5. Adapt your main() to demonstrate polymorphism using this example. Describe clearly how your example demonstrates polymorphism, in around a paragraph.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!