Question: a ) Create a class Book with the following instance variables: o Title: string o Author: string o Number Of Pages: int o Static variable

a) Create a class Book with the following instance variables:
o Title: string
o Author: string
o Number Of Pages: int
o Static variable to track the total number of books created.
1. Include both default and arguments constructors.
2. Implement getters and setters for all instance variables.
3. Implement a method displayInfo() to display book details and a static method getTotalBooks() to show the total number of books.
4. In the main() method, create book objects and display their information.
5. Modify some details using setters.
b) Create a subclass Ebook that inherits from Book that has the following:
1. A new instance variable as file Size then
2. Override/overload the displayInfo() method in Ebook to display the file size in addition.
3. Use an array of Book type, storing both Book and Ebook objects.
4. Handle invalid data (e.g., negative file size) by throwing a custom exception.
Sample Run:
c) Extend the library system to manage multiple types of media (Books, Magazines, DVDs) as follows:
1. Implement an interface Readable with a method void read().
2. Create an abstract class Media with an abstract method void displayMediaInfo() and a concrete method boolean isAvailable().
3. Extend Media in classes Book, Magazine, and DVD, where Book and Magazine implement Readable.
4. Use a 2D array to store media in the library as follows:
Media[][] library = new Media[2][2];
library[0][0]= book; // book is created using Book constructor
library[0][1]= magazine; // magazine is created using Magazine constructor
library[1][0]= dvd; // dvd is created using DVD constructor

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 Programming Questions!