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();
}
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images