Answered step by step
Verified Expert Solution
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()
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 optionsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started