Learning Outcomes
Using Java, maintain a collection of objects using an array.
Construct a class that contains an array as a private instancevariable.
Construct methods with arrays as parameters and returnvalues.
Use partially filled arrays to implement a class where objectscan be dynamically added.
Implement searching and sorting algorithms.
Instructions
For this assignment you will be implementing an application thatmanages a music collection. The application will allow the user toadd albums to the collection and create a playlist of songs fromthat collection. The collection, albums, and playlist should all beimplemented using arrays.
The Song Class
The Song class has the following members:
Private instance variables for the title, artist, and length ofthe song in seconds.
A constructor that takes a title, artist, number of minutes, andnumber of seconds and creates a Song object. The length of the songis calculated by multiplying the number of minutes by 60 and addingthe number of seconds.
Accessor methods for the title, artist, and length.
A method called display that displays a song in the followingformat:
The Album Class
The Album class has the following members:
Private instance variables for the title, artist, and tracklistof the album. The tracklist should be an array of Song objects.
A constructor that takes a title, artist, and an array of Songobjects and initializes the private instance variables. Thetracklist should be initialized by creating a new array and copyingall of the Song objects from the array passed as a parameter.
Accessor methods for the title and artist.
A method called getNumTracks that returns the number of trackson the album.
A method called getTrack that takes a track number between 1 andthe number of tracks, and returns the corresponding song. If thenumber provided is out of range, it returns null.
A method called comesBefore that takes another album as aparameter and returns true if the album the method was called oncomes before the album passed as a parameter. The order isdetermined by the artist first, then the title. UsecompareToIgnoreCase and equalsIgnoreCase to do the artist and titlecomparisons.
A method called displayAlbum that displays the title, artist,and number of tracks in the following format:
Title - Artist (NumTracks tracks)
If the number of tracks is one, it should display 1 track in theparentheses.
The AlbumCollection Class
The AlbumCollection class has the following members:
A public named constant for the maximum number of albums allowedin a collection.
Private instance variables for the number of albums in thecollection, and an array of Album objects.
A default constructor that initializes the number of albums tozero and the array to a new array that can store the maximum numberof albums allowed.
An accessor function for the number of albums.
A boolean method called addAlbum that takes an Album as aparameter. If the collection is full it returns false. Otherwise,it stores the album in the next open spot in the array, andincrements the number of albums.
A method called findAlbum that takes a title and artist asparameters and uses a sequential search to find and return thefirst album it finds with the given title and artist. If no albumis found, it returns null.
A void method called sortAlbums that sorts all of the albums inthe collection using selection sort, with the comesBefore methodfrom the Album class determining the sorting order.
A void method called displayAlbums that displays all of thealbums in the collection.
A void method called displaySongs that displays all of thealbums in the collection along with their track lists.
The Playlist Class
The Playlist class has the following members:
A public named constant for the maximum number of songs allowedin a playlist.
Private instance variables for the number of songs in theplaylist and an array of Song objects.
A default constructor that initializes the number of songs tozero and the array to a new array that can store the maximum numberof songs allowed.
An accessor function for the number of songs.
A method called getLength that returns the total length inseconds of the songs on the playlist.
A boolean method called addSong that takes an Song as aparameter. If the playlist is full, it returns false. Otherwise, itstores the song in the next open spot in the array and incrementsthe number of songs.
A void method called display that displays all of the songs inthe playlist, followed by the total length of the playlist inminutes and seconds.
A void method called clear that empties out the playlist bysetting the number of songs to 0. It does not have to go throughthe array and remove any songs.
The Main Class
The main class should be called YourlastnameProgram3 and has thefollowing members:
A private static method called getChoice that takes noarguments, reads an integer from the user, and returns it.
A private static method called createAlbum that does thefollowing:
Prompt the user for an album title.
Prompt the user for an album artist.
Prompt the user for the number of tracks on the album until theuser enters a value greater than zero.
Call the getTracklist method to prompt the user for the trackson the album and get an array of Song objects.
Create a new Album object with the title, artist, and track listprovided and return it.
Prompt the user for the title and length in minutes and secondsfor each track.
Create a Song object for each track with the informationprovided and store it in an array of Song objects.
Return the array of Song objects.
Prompt for the title and artist to search for.
Call the findAlbum method to find the album in thecollection.
If the album is not found, display a message indicating that thealbum is not in the collection, and go back to step 1.
Otherwise return the album.
Display the tracklist for the album.
Prompt the user to choose a track number.
Call the getTrack method to get the song with the given tracknumber.
If the track number is not valid, go back to step 2.
Otherwise, return the song.
Create an empty AlbumCollection and an empty Playlist
Display a welcome message.
Call displayMenu to display the menu.
Call getChoice to get the user’s choice.
If the choice is 1, call createAlbum to create a new album andadd the album to the collection.
If the choice is 2, display the albums in the collection.
If the choice is 3, display the songs in the collection.
If the choice is 4, sort the albums in the collection.
If the choice is 5, call getAlbumFromCollection to select analbum, call getSongFromAlbum to select a song, and add the song tothe playlist.
If the choice is 6, display the playlist.
If the choice is 7, clear the playlist.
If the choice is 8, display a thank you message.
If the choice is any other value, display an error message.
Go back to step 3 unless the choice was 8.