Learning Objectives: To be able to code a class structure with attributes and methods with appropriate access specifiers. To demonstrate the concepts of inheritance, abstract classes and interfaces. Provide practice creating objects of different types, overloaded methods, ArrayLists, encapsulation, and static variables.
Create a set of classes for various types of electronic library content. You will create an abstract class for a general library item, then subclasses for songs, video and books. The abstract parent class will contain common attributes and the subclasses will have unique attributes for each class. Use a static variable to keep track of the total number of objects in the library and to assign unique library ID numbers. Each subclass should include an overloaded constructor for initializing all the values with the exception of the library ID number, which must be encapsulated. The following provides specific guidance for the class structure;
1) Create an abstract class for a library item. Attributes should include title and library ID. The library ID must be encapsulated, using a private access specifier and setters/getters for access.
2) Create a subclass for songs. Attributes should include type and artist.
3) Create a subclass for videos. Attributes should include genre, rating, and running time in minutes.
4) Create a subclass for books. Attributes should include author, number of pages, boolean category fiction/non-fiction.
5) Create an interface (printItem) that is implemented in each subclass. The method will print all the fields of an object.
6) Create at least 3 of each type of object (you may intiialize them within the program, a user interface for input is not required) and store them in an ArrayList for each type. Using a loop and your overridden printItem method, print out all the items in each ArrayList to display the entire library to the user.
7) Use a static variable for total number of objects in the library. Use this count to assign a unique library ID number for each object created. Print out the total number of objects in the library.
The following is an example of what your output might look like:
This program displays information for all the items in the library and the total number of items.
Library item number 1
The song title is Chandelier
The song type is pop
The artist for this song is Sia
Library item number 2
The song title is Sweet Home Chicago
The song type is blues
The artist for this song is Robert Johnson
Library item number 3
The song title is Dynamite
The song type is pop
The artist for this song is BTS
Library item number 4
The book title is Walden
The book author is Thoreau
The book is non-fiction and 450 pages long.
Library item number 5
The book title is Hamlet
The book author is Shakespeare
The book is fiction and 320 pages long.
Library item number 6
The book title is Origin of Species
The book author is Darwin
The book is non-fiction and 250 pages long.
Library item number 7
The video title is Avengers
The video genre is Action
The video is rated PG13 and runs for 160 minutes.
Library item number 8
The video title is Hidden Figures
The video genre is Historical drama
The video is rated PG and runs for 175 minutes.
Library item number 9
The video title is Citizen Kane
The video genre is drama
The video is rated PG and runs for 90 minutes.
The total number of items in the library is 9