Starting from:

$30

CPT120-Tutorial 8 Music Library and Song Solved

Song.java: A Song object cannot be created without a song title and a String containing the location of the song in the computer (e.g. “c:/song.mp3”). It also has the relevant accessor (get) methods but no mutator (set) methods. A Song must not have any methods that will display messages. Only its constructor and the above two methods can be accessed by other classes. Write the code for this in a new class named Song.java.

MusicLibrary.java: A MusicLibrary object cannot be created without a maximum number of songs. A MusicLibrary object also has an array of Song objects (the size of this array can be set to the maximum number of songs specified) and the number of currently added songs. It must not have the separate arrays songTitles and songLocations anymore. Move all of the code from the main method to the constructor first then refactor the code in to different methods so that you have at least one method per menu item. Aside from the methods, no other component of this class should be accessible by other classes. As it is the application class, the MusicLibrary has a main method and this method must contain only the following line (then the return statement):

MusicLibrary ml=new MusicLibrary(100);

In the above, the 100 refers to the maximum number of songs.

You must not create anything static other than public static void main. All object member variables must be private and they must only be initialised inside the constructor (including the creation of arrays). Any references to member variables from within methods should start with “this.”. There is no need for private methods. You will need to write a constructor for each class and you must prevent the creation of objects that are invalid (e.g. don’t create a second constructor that will allow you to create a Song object with no song title or location). Use only standard arrays in Java (e.g. avoid ArrayList, etc.). You must not use break, continue, System.exit(). Use only while loops for repetition. When possible, you must use concepts covered in standard class materials over others.

More products