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();     } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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;
Transcribed Image Text: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;
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);
=
=
Transcribed Image Text: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); = =
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Methods of StringBuilder class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education