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 no-argument constructor which allocates an empty linear linked list with a null
head reference and a length of 0.
public void addSong(String newSongTitle, String newArtist,
String newAlbumTitle, String newTime)
The addSong() method has two cases.
1. 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 1.
2. 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 1.
public void insertSong(String newSongTitle, String newArtist,
String newAlbumTitle, String newTime, int i)
The insertSong() method has three cases.
1. If the given value of i is equal to 0 and the linked list is not empty, this method must
insert the song at the head of the linked list and increase length.
2. 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.
3. Else, this method inserts the song at position i in the linked list, where i is an index
number between 1 and length 1. After inserting the Node, this method
increases length.
public void removeSong(int i)
The removeSong() method has three cases.
1. If the given value of i is equal to 0 and the linked list is not empty, this method must
remove the song at the head of the linked list and decrease length.
2. Else if the given value of i is equal to length 1, this method must traverse to the
second-to-last song in the linked list, remove song at the tail of the linked list, then
decrease length.
3. 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 0.
public String getSongInfo(int 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 0.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!