95.6k views
2 votes
Use the following information to create a program that allows the user to manipulate a music playlist and view its content.

Your program should contain 3 separate classes: a Song class, a Playlist class, and a Demo class.
In this program, the Playlist class will function as a doubly linked list that contains Song objects. The Demo class will be used to make modifications to the Playlist.
Song Class
This class should contain the following fields:
name: String
artist: String
album: String
length: int
This is the length of the song in seconds
next: Song - This is a reference to the song that follows this song in the list
previous: Song -This is a reference to the song that precedes this song in the list
The Song class should contain the appropriate getters and setters for these attributes, a no-arg constructor, and a constructor that accepts the following arguments: name, artist, album, and length.
Playlist Class
This class will act as our doubly linked list. This class should contain the following attributes:
head: Song - A dummy node (a blank song object that will represent the first song in the playlist)
tail: Song - A dummy node (a blank song object that will represent the last song in the playlist)
size: int - The number of songs in the playlist
The Playlist class should also contain the following methods:
A method that accepts a Song object and adds it to the end of the Playlist.
A method that accepts 2 Song objects (a new Song to be added, and a Song that is currently playing from the playlist). This method will insert the new Song into the playlist at the position directly after the Song that is currently playing.
A method that accepts a Song object, returns nothing, and removes the Song from the playlist.
A toString method that prints out the contents of the Playlist. This toString method should also calculate and display the number of songs in the playlist, as well as the length of the playlist in minutes and seconds.
Demo Class
This class will serve to accept user input and manipulate the Playlist doubly linked list.
The Demo class should instantiate a Playlist object and display a menu to the user that will allow for the following actions:
Add a Song to the Playlist
Insert a new Song after the Song that is currently playing
If a song is being added/inserted to an empty playlist, that song should then be set to be the one that is currently playing.
Print the contents of the Playlist
Display the current Song
When displaying the current song for the first time, the first song in the playlist should be displayed.
To accomplish this, create a Song reference variable and assign it the first Song in the Playlist
Remove the current song
When removing the current song, the new current song will be the song that directly follows the removed song.
Skip to the next song
If you are at the end of the Playlist, the next Song should be the first Song in the playlist.
Return to the previous song
USE JAVA ONLY
AND DOUBLY LINKED LIST

User Matt Hinze
by
7.3k points

1 Answer

3 votes

Final answer:

The task is to write a Java program that simulates a music playlist using classes for Songs, Playlist (as a doubly linked list), and Demo for user interactions to manipulate the playlist.

Step-by-step explanation:

The student is asked to create a music playlist program in Java utilizing object-oriented programming principles. Specifically, the program is expected to consist of three classes: Song, Playlist (a doubly linked list), and Demo for interacting with the playlist.

The Song class will contain fields for the song's metadata and pointers to the next and previous songs, effectively forming the nodes of the doubly linked list. The Playlist class will manage these nodes, allowing addition, insertion after the current song, deletion, and displaying of song information. The Demo class will serve as the user interface to interact with the Playlist.

The Playlist's toString method will need to provide details such as the total number of songs and the overall length of the Playlist in minutes and seconds. Functionalities such as adding a song, inserting a song after the current one, removing the current song, skipping to the next song, and returning to the previous song must be implemented through user input in the Demo class.

User Mike Gardiner
by
8.9k points