Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Today, over 400 million people stream music online. But instead of playing songs individually, many people now listen to music playlists that contain one or


Today, over 400 million people stream music online. But instead of playing songs individually, many people now listen to music playlists that contain one or more songs. In this assessment, students will implement a MusicManager class that represents a music playlist as a linked list of songs. Listeners can not only get the next song in the playlist, but they can also preview all the songs in the playlist, remove any song from the playlist, and see all the songs that they've removed in the order of most recently-removed.

By completing this assignments, students will be able to:

Implement a well-designed Java class to meet a given specification.

make a linked list and manipulate linked nodes in an efficient manner.

Follow prescribed conventions for code quality, documentation, and readability

Fields

Unlike prior assignments, the fields of your MusicManager class are part of the specification. Your MusicManager must have exactly these two fields.

A reference to the front node of the current playlist.

A reference to the front node of the removed songs.

All songs initially begin in the current playlist. Songs that are removed from the current playlist are moved to the front of the removed songs by rearranging links between nodes.

Do not include a size field!

MusicNode

We've provided a MusicNodeclass that you should use to implement MusicPlaylist.

Do not modify the MusicNode class.

Constructor

public MusicManager(List songs)

This constructor initializes a new music playlist with the given list of songs. Don't store the given list of songs; instead, iterate over the list and construct a new linked list of MusicNode objects, one node for each song. The songs from the list should be added into the playlist in the same order in which they appear in the original list. Assume that the songs are non-empty non-null strings, and that there are no duplicate songs in the list. This method should throw an IllegalArgumentException if the songs argument is an empty list.

Methods

public void printCurrent()

This method should print the songs in the current playlist, one per line, each line indented by 4 spaces.

public void printRemoved()

This method should print the removed songs, one per line, each line indented by 4 spaces. Songs should appear opposite the order they were removed so that the most recently-removed songs appear first.

public boolean currentContains(String song)

This method should return true if the given song is in the current playlist, and false otherwise. Ignore case when comparing songs, so "all the stars" should match a node with the song "All The Stars".

To ignore case when comparing songs, instead of calling the string method equals, call equalsIgnoreCase.

public boolean removedContains(String song)

This method should return true if the given song is in the list of removed songs, and false otherwise. Ignore case when comparing songs, so "all the stars" should match a node with the song "All The Stars".

public boolean hasSongs()

This method should return true if there are 1 or more songs left in the current playlist.

public String nextSong()

This method should return the next song in the current playlist, or null if there are no songs left.

public void remove(String song)

This method should remove the given song from the current playlist, transferring the MusicNode to the front of the list of removed songs. The order of all other songs should stay the same. Ignore case when comparing songs. Throw an IllegalStateException if there are no songs left to remove. Throw an IllegalArgumentException if the song is not in the current playlist. (If both exception conditions are true, the IllegalStateException takes precedence.)

Try to write simple code and use inline comments to clarify anything complex. Make sure to remove or comment-out any debugging print statements before making your final submission!

-------------------------MusicNode.java------------------------------

public class MusicNode { public final String song; // this node's song (can't modify) public MusicNode next; // next node in the list


// constructs a node with the given song and a null link public MusicNode(String song) { this(song, null); }


// constructs a node with the given song and link public MusicNode(String song, MusicNode next) { this.song = song; this.next = next; } }

--------------MusicManager.java----------------

public class MusicManager {

// code

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

implement the MusicManager class according to the provided specifications you need to utilize the MusicNode class to create a linked list of songs Bel... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Business Ethics

Authors: Peter A. Stanwick, Sarah D. Stanwick

3rd Edition

1506303234, 9781506303239

More Books

Students also viewed these Programming questions