Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please answer only task 2 and use alternative method to Comparator.comparing() The program YourPrime is a digital media library comprising of movies, songs and books.

please answer only task 2 and use alternative method to Comparator.comparing()

image text in transcribedimage text in transcribed

The program YourPrime is a digital media library comprising of movies, songs and books. As a subscriber of this program, you can create a playlist for each media subtype and store these playlists in your MyMedia object. The fees associated with each media subtype are dependent on the genre type and the rating of the media object. Genre is an abstract class with a single instance variable (price) and an abstract method called setPrice (int). The inheritance tree for the class Genre is presented below: These genre subtypes are exclusive to a specific media subtype (indicated by the boxes with dashed-lines), i.e., the Rock, Rap and Pop classes are for Song, the Action, Comedy, and Drama are for Movie and the Fantasy and Autobiography are for Book. However, in the current implementation, there is no constructor validation for our media subtype, therefore it is possible to assign any genre types regardless of the media subtypes, e.g., Book b = new Book("Oliver Twist", "Charles Dickens", 1838, 5, 608, new Rock()); // this should not be allowed ! This is not ideal - more so, this has the potential to create havoc when we want to calculate our subscription fees. One way to handle this issue is to implement a static factory method called of () to handle object instantiation. The of () method will check the validity of the genre according to the media subtype, and return a new object if the check is valid, or throw an Il legalArgumentException otherwise. Inside each Media subtype class, you will find a static factory of () method. Your task is to complete the definition of the method. You need to validate that the genre subtype is valid, before returning a new object. If the genre subtype is invalid, you need to throw an IllegalArgumentException. Task 02: More orderByType variations ( 4 marks) In the existing MyMedia class, you can perform five (5) different sorting operations (by price, rating, title, duration, and number of pages). You are required to add two (2) new sorting operations that will allow subscribers to sort based on the artist (for songs), and authors (for books). Complete the codes for the sort () method in MyMedia class [4 marks - 2 marks each] You need to add two new sorting method (in the sort () method) to compare artists for the Song class (compareByArtist) and authors (compareByAuthor) for the Book class. You are also required to add new conditional statements to enable these sorting options

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mastering Apache Cassandra 3 X An Expert Guide To Improving Database Scalability And Availability Without Compromising Performance

Authors: Aaron Ploetz ,Tejaswi Malepati ,Nishant Neeraj

3rd Edition

1789131499, 978-1789131499

More Books

Students also viewed these Databases questions

Question

1. Signs and symbols of the map Briefly by box ?

Answered: 1 week ago

Question

Types of physical Maps?

Answered: 1 week ago

Question

Explain Intermediate term financing in detail.

Answered: 1 week ago