0.) Design a hierarchy of classes, where the Media superclass has the artistName and the mediaName as the common attributes. Create a subclass called CDMedia that has the additional arrayList of String objects containing the songs per album. Create another subclass called DVDMedia that has the additional year the movie came out, and an arrayList of co-stars for the movie.
1.) The superclass Media will implement Comparable, and will define a compareTo() method based on mediaName.
2.) Create another class, ComparatorByArtistName, which will implement the Comparator interface, and will define the compare() method based on artistName.
3.) Using the attached catalog2.txt file, create a driver class that creates an arrayList of type Media, which contains individual objects of CDMedia and DVDMedia. Print the entire arrayList of Media once after sorting them by mediaName. Display the entire content of the Media. Then, print a dividing line of asterisks, and print the entire arrayList of Media again after sorting them by artistName.
4.) Display a menu for the user to select from the following options:
1. Search by Media Title (movie name or album name)
2. Search by Artist (singer or actor)
3. Add media to catalog
4. Quit
In order to do a binarySearch method, you must create a search object with the value in the field of what you are searching for. Thus, if you are searching for a media name, create a Media object with only the value of the media name in it. If you are searching for an artist, then create a Media object with only the value of the artist in it. See the Java API for the Collections class, to look up the format of the binarySearch method.
5.) For the media search, first sort the ArrayList of Media by media name, using the Comparable interface and compareTo method in the Media class. Then, use the binary search method for Collections, Collections.binarySearch(), to find the media requested by the user, for a specific media name. Display the entire Media object that matches the media name supplied.
6.) For the artist search, sort the ArrayList of Media by artist name, using your comparator class. Once sorted by artist, use the binary search method for Collections, Collections.binarySearch() to find all the media for a particular artist requested by the user. Display all the Media objects that match the artist name supplied.
***Hint: Since there are multiple media objects with the same artist name, the value returned by the binarySearch() method is an arbitrary index in the arrayList of Media objects with the same artist. You will have to keep getting the rest of the Media objects by searching above and below that arbitrary index, until the artist is different. Use the ArrayList.get()method (see page 349 of Big Java, 5th Edition, for an example of a loop to sequentially go through an arrayList.)
7.) Implement the Scanner and File classes to read the catalog2.txt file.
8.) Implement the FileWriter and PrintWriter classes to write to the Media file.
9.) Thus, prompt the user for the name of the input/output file. Catch exceptions such as IOException and FileNotFound. Give the user a message that says "Enter catalog2.txt for the file input."
10.) If the user selects the "add media to catalog" option, then prompt the user for all the information that makes up a CDMedia object or a DVDMedia object, and once created, add the new object to the ArrayList of Media. Don't forget to permanently add the media record to the external file, using the FileWriter and PrintWriter classes. It may be easier to create a .toString() method in the specific media subclass, and then use it to write the new Media record to the file. (Ex.: output.println(objectName) will invoke the .toString()) behind the scenes.) Remember to add the C or D as the first field for a CDMedia or a DVDMedia record.
11.) When adding a new record to the catalog2.txt file, if the user enters a non-numeric field wherever a number is required (i.e. year), then catch that numberFormatException, and give the user a chance to enter that field again.
12.) If the user is adding a DVDMedia record to the catalog2.txt file, make sure to loop for all the co-stars of that movie. If the user is adding a CDMedia record to the catalog2.txt file, make sure to loop for all the songs in that album. In both of these records, you will have an arrayList of co-stars, or an arrayList of songs, as part of the object.