Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using an inheritance hierarchy, design a Java program to model items at a librar

ID: 3680946 • Letter: U

Question

Using an inheritance hierarchy, design a Java program to model items at a library (books, journal articles, videos and CDs.) Have an abstract superclass called Item and include common information that the library must have for every item (such as unique identification number, title, and number of copies). No actual objects of type Item will be created - each actual item will be an object of a (non-abstract) subclass. Place item-type-specific behavior in subclasses (such as a video's year of release, a CD's musical genre, or a book's author).
More in detail:

1. Implement an abstract superclass called Item and define all common operations on this class (constructors, getters, setters, equals, toString, print, checkIn, checkOut, addItem, etc). Have private data for: identification number, title, and number of copies.

2. Implement an abstract subclass of Item named WrittenItem and define all common operations on this class. Added private data for author.

3. Implement 2 subclasses of WrittenItem: Book and JournalPaper.


3.1. Class Book: no new private data. When needed, override/overload methods from the superclass.
3.2. Class JournalPaper: added private data for year published. When needed, override/overload methods from the superclass.


4. Implement another abstract subclass of Item named MediaItem and define all common operations on this class. Added private data for runtime (integer).

5. Implement 2 subclasses of MediaItem: Video and CD.

5.1. Class Video: added private data for director, genre and year released. When needed, override/overload methods from the superclass.
5.2. Class CD: added private data for artist and genre. When needed, override/overload methods from the superclass.

Write the definitions of these classes and a client program (your choice!) showing them in use. Some possible output could look like this:

Display info about a book
ID: 123456
TITLE: To kill a mocking bird
AUTHOR: Harper Lee
NUMBER OF COPIES: 5
After the book was checked-out, the number of copies changed. The new info is:
Display info about a book
ID: 123456
TITLE: To kill a mocking bird
AUTHOR: Harper Lee
NUMBER OF COPIES: 4
After a new copy of this book was added, the number of copies changed. The new info is:
Display info about a book
ID: 123456
TITLE: To kill a mocking bird
AUTHOR: Harper Lee
NUMBER OF COPIES: 5
Display info about a video
ID: 1111
TITLE: The Godfather
DIRECTOR: Francis Ford Coppola
GENRE: drama
YEAR RELEASED: 1981
RUNTIME: 215.0 minutes
NUMBER OF COPIES: 3
After the video was checked-in, the number of copies changed. The new info is:
Display info about a video
ID: 1111
TITLE: The Godfather
DIRECTOR: Francis Ford Coppola
GENRE: drama
YEAR RELEASED: 1981
RUNTIME: 215 minutes
NUMBER OF COPIES: 4
...
...

Explanation / Answer

abstract class Item { int id; String title; int copies; public Item(int id, String title, int copies) { this.id = id; this.title = title; this.copies = copies; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Item item = (Item) o; if (id != item.id) return false; if (copies != item.copies) return false; return !(title != null ? !title.equals(item.title) : item.title != null); } @Override public String toString() { return "Item{" + "id=" + id + ", title='" + title + ''' + ", copies=" + copies + '}'; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public int getCopies() { return copies; } public void setCopies(int copies) { this.copies = copies; } } abstract class WrittenItem extends Item{ String author; public WrittenItem(int id, String title, int copies) { super(id, title, copies); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; WrittenItem that = (WrittenItem) o; return !(author != null ? !author.equals(that.author) : that.author != null); } @Override public String toString() { return "WrittenItem{" + "author='" + author + ''' + '}'; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } } class Book extends WrittenItem{ public Book(int id, String title, int copies) { super(id, title, copies); } } class JournalPaper extends WrittenItem{ int yearPublished; public JournalPaper(int id, String title, int copies) { super(id, title, copies); } } abstract class MediaItem extends Item{ int runtime; public MediaItem(int id, String title, int copies) { super(id, title, copies); } public int getRuntime() { return runtime; } public void setRuntime(int runtime) { this.runtime = runtime; } } class Video extends MediaItem{ String director; String genre; int yearReleased; public Video(int id, String title, int copies) { super(id, title, copies); } public String getDirector() { return director; } public void setDirector(String director) { this.director = director; } public String getGenre() { return genre; } public void setGenre(String genre) { this.genre = genre; } public int getYearReleased() { return yearReleased; } public void setYearReleased(int yearReleased) { this.yearReleased = yearReleased; } } class CD extends MediaItem{ String artist; String genre; public CD(int id, String title, int copies) { super(id, title, copies); } public String getArtist() { return artist; } public void setArtist(String artist) { this.artist = artist; } public String getGenre() { return genre; } public void setGenre(String genre) { this.genre = genre; } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote