Question: implement an ADT named Playlist. Playlist will simulate a music playlist using an interface and a linear linked list behind that interface. Each Node in
implement an ADT named Playlist. Playlist will simulate a music playlist
using an interface and a linear linked list behind that interface.
Each Node in the linear linked list will be a record which is an object with several data fields
encapsulated within it In this case, each node will contain four pieces of information about a
song: song title, artist name, album title and run time of the song.
Your ADT Playlist must perform all of the necessary operations to allow a client program to
assemble, edit and play a linear linked list of songs. Your ADT Playlist must have only two
private variables, head and length. head will be a reference to the first node in the linear
linked list and length will be the integer number of nodes in the linked list.
The interface for your ADT Playlist, its wall of operations must consist of the following
methods:
public Playlist
The noargument constructor which allocates an empty linear linked list with a null
head reference and a length of
public void addSongString newSongTitle, String newArtist,
String newAlbumTitle, String newTime
The addSong method has two cases.
If the linked list is empty, this method must add the song to the head of the linked
list and will have to update the length variable, to show that the length of the
list is now
Else, the addSong method must add the song to the tail of the linked list and will
have to update the length variable, to show that the length of the list has increased
by
public void insertSongString newSongTitle, String newArtist,
String newAlbumTitle, String newTime, int i
The insertSong method has three cases.
If the given value of i is equal to and the linked list is not empty, this method must
insert the song at the head of the linked list and increase length.
Else if the given value of i is equal to the length of the linked list, this method
must insert the song at the tail of the linked list and increase length.
Else, this method inserts the song at position i in the linked list, where i is an index
number between and length After inserting the Node, this method
increases length.
public void removeSongint i
The removeSong method has three cases.
If the given value of i is equal to and the linked list is not empty, this method must
remove the song at the head of the linked list and decrease length.
Else if the given value of i is equal to length this method must traverse to the
secondtolast song in the linked list, remove song at the tail of the linked list, then
decrease length.
Else, using references prev and curr, this method must traverse to the song at
position i remove the song at position i then decrease length.
public void removeAllSongs
The removeAllSongs method sets head to null and length to
public String getSongInfoint i
The getSongInfo method returns a String containing the songTitle, artist,
albumTitle and run time for the song at the given position i in the linked list.
public int size
The size method returns the value of the private length variable.
public boolean isEmpty
Returns true if and only if head is null and length is
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
