// The JukeBox should support all the features described in the problem statement. // It has a collection of PlayLists and a MediaPlayer. The main components // of the implementation are the following. // 1. Loading playlists from files. You can create playlists by reading them from // a text file. Implement the method loadPlayListFromFile as // described in greater detail later in this document. This method uses the // PlayListReader class to obtain an ArrayList of strings that it processes to // create and return a new play list. These playlists can then to added to the // collection of the JukeBox using the addPlayList method. // 2. Search for tracks. You can search for tracks by title and by the name of the // artist. these searches are very similar to the Approximate or SubString search as // described in PlayList.java. However, now you will have to search through all the // playlists that are present in the collection of playlists in the JukeBox. So // it will be easier to implement the search methods in the playlist first. // 3. Making requests. You can request for playlists to be played in the media // player (using the addPlayListToRequestQueue method). The juke box will have // to maintain a collection of requested playlists. // When the play() method of the JukeBox is invoked, a new playlist is // created that has all the tracks in all the requested playlists. // This playlist is sent to the play method of the Media Player and the tracks // are played on the media player (not really, only the track names are displayed :) // Calling the play method must empty the collections of requested playlists, since // they have already been played. // Typical interaction. // JukeBox j = new JukeBox(); // PlayList p1 = j.loadPlayListFromFile("..."); specify the file name here. // PlayList p2 = j.loadPlayListFromFile("..."); // ... // PlayList s1 = j.searchByTrackName("hotel cal"); // j.addPlayListToRequestQueue(s1); // PlayList s2 = j.searchByArtistName("eatles"); // j.addPlayListToRequestQueue(s2); // ... // j.play(); // The whole process of searching and making requests and playing will then repeat import java.util.ArrayList; import java.util.Iterator; public class JukeBox{ // The instance variables - the collections of playlists, the collection of // requested playlists. // The player that is accepting requests from this JukeBox private MediaPlayer mplayer; // Other instance variables... private ArrayList playlistCollection; // The collection of playlists that have // been added to the JukeBox private ArrayList requestedPlayLists; // The playlists that have been added to the // request queue // Constructor - initializes the JukeBox public JukeBox(){ // The media player mplayer = new MediaPlayer(); // Everything else that needs to get initialized must goes here playlistCollection = new ArrayList(); requestedPlayLists = new ArrayList(); } // Get/Set/Add properties // Add the playlist to the collection of playlists maintained by the // JukeBox. Return the number of playlists in the collection public int addPlayList(PlayList playlist){ playlistCollection.add(playlist); return playlistCollection.size(); } // Express the contents of the JukeBox in a single string. This string must // include all the play lists in the jukebox collection (with their tracks), // and also identify the playlists (with the tracks) that are in the requestQueue // Add newlines ("\n") to the return string, so that if it were printed, the // string will be readable. // NOTE: A string is computed and returned, NOT printed right here. public String toString(){ String result = "Playlists in the JukeBox Collection \n\n"; for(int i=0; i