Given main(), complete the SongNode class to include the printSongInfo() method. Then write the Playlist class' printPlaylist() method to print all songs in the playlist. DO NOT print the dummy head node. Ex: If the input is: Stomp! 380 The Brothers Johnson The Dude 337 Quincy Jones You Don't Own Me 151 Lesley Gore -1 the output is: LIST OF SONGS ------------- Title: Stomp! Length: 380 Artist: The Brothers Johnson Title: The Dude Length: 337 Artist: Quincy Jones Title: You Don't Own Me Length: 151 Artist: Lesley Gore class SongNode { // Fields for song information and reference to the next node private String title; private int length; private String artist; private SongNode next; // Constructors for creating SongNode instances public SongNode() { title = ""; length = 0; artist = ""; next = null; } public SongNode(String title, int length, String artist) { this.title = title; this.length = length; this.artist = artist; this.next = null; } // Method to insert a new node after the current node public void insertAfter(SongNode node) { node.next = this.next; this.next = node; } // Accessor for the next node public SongNode getNext() { return next; } // Method to print song information public void printSongInfo() { System.out.println("Title: " + title); System.out.println("Length: " + length); System.out.println("Artist: " + artist); System.out.println(); } }
Given main(), complete the SongNode class to include the printSongInfo() method. Then write the Playlist class' printPlaylist() method to print all songs in the playlist. DO NOT print the dummy head node.
Ex: If the input is:
Stomp! 380 The Brothers Johnson The Dude 337 Quincy Jones You Don't Own Me 151 Lesley Gore -1
the output is:
LIST OF SONGS ------------- Title: Stomp! Length: 380 Artist: The Brothers Johnson Title: The Dude Length: 337 Artist: Quincy Jones Title: You Don't Own Me Length: 151 Artist: Lesley Gore
class SongNode {
// Fields for song information and reference to the next node
private String title;
private int length;
private String artist;
private SongNode next;
// Constructors for creating SongNode instances
public SongNode() {
title = "";
length = 0;
artist = "";
next = null;
}
public SongNode(String title, int length, String artist) {
this.title = title;
this.length = length;
this.artist = artist;
this.next = null;
}
// Method to insert a new node after the current node
public void insertAfter(SongNode node) {
node.next = this.next;
this.next = node;
}
// Accessor for the next node
public SongNode getNext() {
return next;
}
// Method to print song information
public void printSongInfo() {
System.out.println("Title: " + title);
System.out.println("Length: " + length);
System.out.println("Artist: " + artist);
System.out.println();
}
}
![1 public class Playlist {
1234567
2
7
8
9
10
11
12
13
14
15
16
17
67
Current file: Playlist.java →
// Method to print the playlist
public static void printPlaylist (SongNode headNode) {
SongNode currentNode = headNode.getNext(); // Start from the first actual nod
while (currentNode != null) {
currentNode.printSongInfo();
currentNode currentNode.getNext();
=
}
}
public static void main(String[] args) {
scanner scnr = new scanner (System.in);
SongNode headNode;
SongNode currNode;
SongNode lastNode;
String songTitle;
int songLength;
String songArtist;](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Faad9e4ed-ed50-4fe3-96ca-72ed3d364f6f%2F0d747854-7966-4006-9599-dfce9daaad44%2Fbw2mfpk_processed.png&w=3840&q=75)
![19
20
21
22
23
NO
4567
24
25
NN
26
N N N M m m m m m
27
28
29
WNHO is
30
31
32
33
34
P
560
35
36
headNode new SongNode();
lastNode headNode;
// Reading user input and creating nodes
songTitle = scnr.nextLine();
while (!songTitle.equals("-1")) {
scnr.nextInt ();
songLength
scnr.nextLine();
songArtist = scnr.nextLine();
// Creating a new node and inserting it into the playlist
currNode = new SongNode (songTitle, songLength, songArtist);
lastNode.insertAfter (currNode);
lastNode = currNode;
songTitle
}
scnr.nextLine();
System.out.println("LIST OF SONGS");
System.out.println("-
------ ");
printPlaylist (headNode);
=
=](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Faad9e4ed-ed50-4fe3-96ca-72ed3d364f6f%2F0d747854-7966-4006-9599-dfce9daaad44%2Fb7q7sei_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)