Question: Write a java program: We are going to practice creating a hierarchy of classes (inheritance), polymorphism and interfaces. Your program will simulate a media library.

Write a java program: We are going to practice creating a hierarchy of classes (inheritance), polymorphism and interfaces. Your program will simulate a media library. We will work with four types of media: books, pictures, music, and movies. Your job is to design and implement a class hierarchy consisting of the Media, Picture, Music, Movie, and Book classes, as described below.

Media class

This class should be an abstract class.

A Media object has a name, and a rating. The rating is an integer number. You need to implement the constructors, accessor, and mutator methods as needed.

This class should have two abstract methods: toString method will be used to collect and return (as a String) all of

the information of a Media object.

getMediaType method will be used to return (as a String) the type of a Media object (such as Book, Movie, Music, Picture).

Book class

A Book is a kind of Media that has an author and a number of pages. Book should implement the toString and getMediaType methods of Media. The toString method displays all the book information, including media type, name, author, number of pages, and rating. Make sure you also implement any other methods (such as constructor, accessor, and mutator) as needed by Book.

Movie class

A Movie is a kind of Media that has a director. Movie should implement the toString and getMediaType methods of Media. The toString method displays all the movie information, including media type, name, director, and rating. Make sure you also implement any other methods (such as constructor, accessor, and mutator) as needed by Movie.

Music class

A Music is a kind of Media that has an artist. Music should implement the toString and getMediaType methods of Media. The toString

method displays all the music information, including media type, name, artist, and rating. Make sure you also implement any other methods (such as constructor, accessor, and mutator) as needed by Music.

Picture class

A Picture is a kind of Media that has a resolution. The resolution of a picture is an integer number that measures the dot per inch. Picture should implement the toString and getMediaType methods of Media. The toString method displays all the picture information, including media type, name, resolution, and rating. Make sure you also implement any other methods (such as constructor, accessor, and mutator) as needed by Picture.

Test class

Implement a test class to simulate a media library. You should have an array of Media that stores at least 14 different objects of types: Music, Book, Movie, or Picture.

You will provide the information for each media object when you populate the array (see pages 457 and 458 in the textbook for an example on how to populate an array of objects). After the array is populated, display the entire array, using a for loop and the toString method.

Now you will sort the array of Media object by rating. You will do this by using the sort() method of the Arrays class. In order be able to invoke the sort() method you will need to go back to the Media class and say that you are implementing the Comparable interface and then implement the compareTo() method.

Here is a sample run of a typical solution to this problem:

Write a java program: We are going to practice creating a hierarchy

Media in our librar Movie: Harry Potter and the Sorcerer's Stone by Chris Columbus is rated 5 stars Movie: Up by Pete Docter and Bob Peterson is rated 5 stars. Music: You're Still The One by Shania Twain is rated 4 stars Picture: Cats.jpg, 200 dpi, is rated 5 stars. Book: A Brief History of Time by Stephen Hawking, 212 pages, is rated 5 stars. Music: Eye of The Tiger by Survivor is rated 3 stars. Book: A Tale of Two Cities by Charles Dickens, 262 pages, is rated 4 stars Movie: Pride and Prejudice by Joe Wright is rated 4 stars. Picture: Arch.ipg,300 dpi, is rated 3 stars Picture: Towers.jpg, 100 dpi, is rated 2 stars. Picture: Flowers.jpg, 400 dpi, is rated 5 stars. Music: Yellow Submarine by The Beatles is rated 5 stars. Book: The Hobbit by J. R. R. Tolkien, 300 pages, is rated 3 stars. Book: The Alchemist by Paulo Coelho, 208 pages, is rated 4 stars All Media sorted by rating Movie: Harry Potter and the Sorcerer's Stone by Chris Columbus is rated 5 stars. Movie: Up by Pete Docter and Bob Peterson is rated 5 stars. Picture: Cats.jpg, 200 dpi, is rated 5 stars. Book: A Brief History of Time by Stephen Hawking, 212 pages, is rated 5 stars. Picture: Flowers.jpg, 400 dpi, is rated 5 stars. Music: Yellow Submarine by The Beatles is rated 5 stars. Music: You're Still The One by Shania Twain is rated 4 stars. Book: A Tale of Two Cities by Charles Dickens, 262 pages, is rated 4 stars. Movie: Pride and Prejudice by Joe Wright is rated 4 stars. Book: The Alchemist by Paulo Coelho, 208 pages, is rated 4 stars. Music: Eye of The Tiger by Survivor is rated 3 stars. Picture: Arch.ipg, 300 dpi, is rated 3 stars. Book: The Hobbit by J. R. R. Tolkien, 300 pages, is rated 3 stars. Picture:Towers.jpg, 100 dpi, is rated 2 stars. Media in our librar Movie: Harry Potter and the Sorcerer's Stone by Chris Columbus is rated 5 stars Movie: Up by Pete Docter and Bob Peterson is rated 5 stars. Music: You're Still The One by Shania Twain is rated 4 stars Picture: Cats.jpg, 200 dpi, is rated 5 stars. Book: A Brief History of Time by Stephen Hawking, 212 pages, is rated 5 stars. Music: Eye of The Tiger by Survivor is rated 3 stars. Book: A Tale of Two Cities by Charles Dickens, 262 pages, is rated 4 stars Movie: Pride and Prejudice by Joe Wright is rated 4 stars. Picture: Arch.ipg,300 dpi, is rated 3 stars Picture: Towers.jpg, 100 dpi, is rated 2 stars. Picture: Flowers.jpg, 400 dpi, is rated 5 stars. Music: Yellow Submarine by The Beatles is rated 5 stars. Book: The Hobbit by J. R. R. Tolkien, 300 pages, is rated 3 stars. Book: The Alchemist by Paulo Coelho, 208 pages, is rated 4 stars All Media sorted by rating Movie: Harry Potter and the Sorcerer's Stone by Chris Columbus is rated 5 stars. Movie: Up by Pete Docter and Bob Peterson is rated 5 stars. Picture: Cats.jpg, 200 dpi, is rated 5 stars. Book: A Brief History of Time by Stephen Hawking, 212 pages, is rated 5 stars. Picture: Flowers.jpg, 400 dpi, is rated 5 stars. Music: Yellow Submarine by The Beatles is rated 5 stars. Music: You're Still The One by Shania Twain is rated 4 stars. Book: A Tale of Two Cities by Charles Dickens, 262 pages, is rated 4 stars. Movie: Pride and Prejudice by Joe Wright is rated 4 stars. Book: The Alchemist by Paulo Coelho, 208 pages, is rated 4 stars. Music: Eye of The Tiger by Survivor is rated 3 stars. Picture: Arch.ipg, 300 dpi, is rated 3 stars. Book: The Hobbit by J. R. R. Tolkien, 300 pages, is rated 3 stars. Picture:Towers.jpg, 100 dpi, is rated 2 stars

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!