SlideShare a Scribd company logo
1 of 3
Download to read offline
It's not working what am I doing wrong?
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:
the output is:
import java.util.Scanner;
public class Playlist {
// TODO: Write method to ouptut list of songs
public static void printPlaylist(SongNode songs){
SongNode song = song.getNext();
while (song != null) {
song.printSongInfo();
System.out.println();
song = song.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;
// Front of nodes list
headNode = new SongNode();
lastNode = headNode;
// Read user input until -1 entered
songTitle = scnr.nextLine();
while (!songTitle.equals("-1")) {
songLength = scnr.nextInt();
scnr.nextLine();
songArtist = scnr.nextLine();
currNode = new SongNode(songTitle, songLength, songArtist);
lastNode.insertAfter(currNode);
lastNode = currNode;
songTitle = scnr.nextLine();
}
// Print linked list
System.out.println("LIST OF SONGS");
System.out.println("-------------");
printPlaylist(headNode);
}
}
public class SongNode {
private String songTitle;
private int songLength;
private String songArtist;
private SongNode nextNodeRef; // Reference to the next node
public SongNode() {
songTitle = "";
songLength = 0;
songArtist = "";
nextNodeRef = null;
}
// Constructor
public SongNode(String songTitleInit, int songLengthInit, String songArtistInit) {
this.songTitle = songTitleInit;
this.songLength = songLengthInit;
this.songArtist = songArtistInit;
this.nextNodeRef = null;
}
// Constructor
public SongNode(String songTitleInit, int songLengthInit, String songArtistInit, SongNode
nextLoc) {
this.songTitle = songTitleInit;
this.songLength = songLengthInit;
this.songArtist = songArtistInit;
this.nextNodeRef = nextLoc;
}
// insertAfter
public void insertAfter(SongNode nodeLoc) {
SongNode tmpNext;
tmpNext = this.nextNodeRef;
this.nextNodeRef = nodeLoc;
nodeLoc.nextNodeRef = tmpNext;
}
// Get location pointed by nextNodeRef
public SongNode getNext() {
return this.nextNodeRef;
}
// TODO: Write printSongInfo() method
public void printInfo(){
System.out.println("Title: " + songTitle);
System.out.println("Length: " + songLength);
System.out.println("Artist: " + songArtist);
}
}

More Related Content

Similar to It's not working what am I doing wrong- Given main()- complete the Son.pdf

maincpp include ltiostreamgt include ltstringgt.pdf
maincpp  include ltiostreamgt include ltstringgt.pdfmaincpp  include ltiostreamgt include ltstringgt.pdf
maincpp include ltiostreamgt include ltstringgt.pdf
mukulsingh0025
 
Can someone please help me implement the addSong function .pdf
Can someone please help me implement the addSong function .pdfCan someone please help me implement the addSong function .pdf
Can someone please help me implement the addSong function .pdf
akshpatil4
 
Program 02 Based on the previous problem you should impleme.pdf
Program 02 Based on the previous problem you should impleme.pdfProgram 02 Based on the previous problem you should impleme.pdf
Program 02 Based on the previous problem you should impleme.pdf
addtechglobalmarketi
 
I need help writing the methods for the song and playList class in J.pdf
I need help writing the methods for the song and playList class in J.pdfI need help writing the methods for the song and playList class in J.pdf
I need help writing the methods for the song and playList class in J.pdf
arihanthtextiles
 
Write a program in C++ language that implements a music play.pdf
Write a program in C++ language that implements a music play.pdfWrite a program in C++ language that implements a music play.pdf
Write a program in C++ language that implements a music play.pdf
iconsystemsslm
 
Program 01 For this program you will complete the program in.pdf
Program 01 For this program you will complete the program in.pdfProgram 01 For this program you will complete the program in.pdf
Program 01 For this program you will complete the program in.pdf
addtechglobalmarketi
 
Many of us have large digital music collections that are not always .pdf
Many of us have large digital music collections that are not always .pdfMany of us have large digital music collections that are not always .pdf
Many of us have large digital music collections that are not always .pdf
fazanmobiles
 
819 LAB Program Playlist c++ You will be building a li.pdf
819 LAB Program Playlist c++ You will be building a li.pdf819 LAB Program Playlist c++ You will be building a li.pdf
819 LAB Program Playlist c++ You will be building a li.pdf
meenaaarika
 
In C++ please I need output please You will be building a .pdf
In C++ please I need output please   You will be building a .pdfIn C++ please I need output please   You will be building a .pdf
In C++ please I need output please You will be building a .pdf
sunilverma8487
 
Here is the code.compile g++ Playlist.cpp main.cppPlaylist.h.pdf
Here is the code.compile  g++ Playlist.cpp main.cppPlaylist.h.pdfHere is the code.compile  g++ Playlist.cpp main.cppPlaylist.h.pdf
Here is the code.compile g++ Playlist.cpp main.cppPlaylist.h.pdf
ANANDSALESINDIA105
 
8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf
8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf
8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf
arenamobiles123
 
Need help with this java project, as the methods are proving to be p.pdf
Need help with this java project, as the methods are proving to be p.pdfNeed help with this java project, as the methods are proving to be p.pdf
Need help with this java project, as the methods are proving to be p.pdf
prajeetjain
 
PLEASE I need help with my assignment I have to compelet .pdf
PLEASE I need help with my assignment I have to compelet  .pdfPLEASE I need help with my assignment I have to compelet  .pdf
PLEASE I need help with my assignment I have to compelet .pdf
ankit11134
 
PFB cpp code for the given problem#include iostream #include .pdf
PFB cpp code for the given problem#include iostream #include .pdfPFB cpp code for the given problem#include iostream #include .pdf
PFB cpp code for the given problem#include iostream #include .pdf
mailadmin1
 
Structuring Music Using Linked Lists
Structuring Music Using Linked ListsStructuring Music Using Linked Lists
Structuring Music Using Linked Lists
Cynthia Marcello
 
Hi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdf
Hi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdfHi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdf
Hi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdf
apleathers
 
I am having the below compile errors. .pdf
I am having the below compile errors. .pdfI am having the below compile errors. .pdf
I am having the below compile errors. .pdf
dbrienmhompsonkath75
 
For this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdfFor this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdf
herminaherman
 
a) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdfa) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdf
MAYANKBANSAL1981
 

Similar to It's not working what am I doing wrong- Given main()- complete the Son.pdf (20)

maincpp include ltiostreamgt include ltstringgt.pdf
maincpp  include ltiostreamgt include ltstringgt.pdfmaincpp  include ltiostreamgt include ltstringgt.pdf
maincpp include ltiostreamgt include ltstringgt.pdf
 
Can someone please help me implement the addSong function .pdf
Can someone please help me implement the addSong function .pdfCan someone please help me implement the addSong function .pdf
Can someone please help me implement the addSong function .pdf
 
Program 02 Based on the previous problem you should impleme.pdf
Program 02 Based on the previous problem you should impleme.pdfProgram 02 Based on the previous problem you should impleme.pdf
Program 02 Based on the previous problem you should impleme.pdf
 
I need help writing the methods for the song and playList class in J.pdf
I need help writing the methods for the song and playList class in J.pdfI need help writing the methods for the song and playList class in J.pdf
I need help writing the methods for the song and playList class in J.pdf
 
Write a program in C++ language that implements a music play.pdf
Write a program in C++ language that implements a music play.pdfWrite a program in C++ language that implements a music play.pdf
Write a program in C++ language that implements a music play.pdf
 
Program 01 For this program you will complete the program in.pdf
Program 01 For this program you will complete the program in.pdfProgram 01 For this program you will complete the program in.pdf
Program 01 For this program you will complete the program in.pdf
 
Many of us have large digital music collections that are not always .pdf
Many of us have large digital music collections that are not always .pdfMany of us have large digital music collections that are not always .pdf
Many of us have large digital music collections that are not always .pdf
 
819 LAB Program Playlist c++ You will be building a li.pdf
819 LAB Program Playlist c++ You will be building a li.pdf819 LAB Program Playlist c++ You will be building a li.pdf
819 LAB Program Playlist c++ You will be building a li.pdf
 
In C++ please I need output please You will be building a .pdf
In C++ please I need output please   You will be building a .pdfIn C++ please I need output please   You will be building a .pdf
In C++ please I need output please You will be building a .pdf
 
Here is the code.compile g++ Playlist.cpp main.cppPlaylist.h.pdf
Here is the code.compile  g++ Playlist.cpp main.cppPlaylist.h.pdfHere is the code.compile  g++ Playlist.cpp main.cppPlaylist.h.pdf
Here is the code.compile g++ Playlist.cpp main.cppPlaylist.h.pdf
 
8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf
8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf
8.15 Program Playlist (C++) You will be building a linked list. Mak.pdf
 
Need help with this java project, as the methods are proving to be p.pdf
Need help with this java project, as the methods are proving to be p.pdfNeed help with this java project, as the methods are proving to be p.pdf
Need help with this java project, as the methods are proving to be p.pdf
 
PLEASE I need help with my assignment I have to compelet .pdf
PLEASE I need help with my assignment I have to compelet  .pdfPLEASE I need help with my assignment I have to compelet  .pdf
PLEASE I need help with my assignment I have to compelet .pdf
 
PFB cpp code for the given problem#include iostream #include .pdf
PFB cpp code for the given problem#include iostream #include .pdfPFB cpp code for the given problem#include iostream #include .pdf
PFB cpp code for the given problem#include iostream #include .pdf
 
Structuring Music Using Linked Lists
Structuring Music Using Linked ListsStructuring Music Using Linked Lists
Structuring Music Using Linked Lists
 
Hi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdf
Hi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdfHi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdf
Hi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdf
 
I am having the below compile errors. .pdf
I am having the below compile errors. .pdfI am having the below compile errors. .pdf
I am having the below compile errors. .pdf
 
BeepComp - Chiptune Creator - User's Guide (v0.2.2)
BeepComp - Chiptune Creator - User's Guide (v0.2.2)BeepComp - Chiptune Creator - User's Guide (v0.2.2)
BeepComp - Chiptune Creator - User's Guide (v0.2.2)
 
For this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdfFor this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdf
 
a) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdfa) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdf
 

More from aanyajoshi90

JCL Inc- is a major chip manufacturing firm that sells its products to.pdf
JCL Inc- is a major chip manufacturing firm that sells its products to.pdfJCL Inc- is a major chip manufacturing firm that sells its products to.pdf
JCL Inc- is a major chip manufacturing firm that sells its products to.pdf
aanyajoshi90
 

More from aanyajoshi90 (20)

Jamal has red hair- Since the gene for red hair is recessive- Jamal mu.pdf
Jamal has red hair- Since the gene for red hair is recessive- Jamal mu.pdfJamal has red hair- Since the gene for red hair is recessive- Jamal mu.pdf
Jamal has red hair- Since the gene for red hair is recessive- Jamal mu.pdf
 
Jake stole a suspension of Bacillus anthracis with a known concentrati.pdf
Jake stole a suspension of Bacillus anthracis with a known concentrati.pdfJake stole a suspension of Bacillus anthracis with a known concentrati.pdf
Jake stole a suspension of Bacillus anthracis with a known concentrati.pdf
 
Ivanhoe arovides shutile service between 4 hotels near a medical cente.pdf
Ivanhoe arovides shutile service between 4 hotels near a medical cente.pdfIvanhoe arovides shutile service between 4 hotels near a medical cente.pdf
Ivanhoe arovides shutile service between 4 hotels near a medical cente.pdf
 
its about the economic systems of Haiti XI- Economic Policies and Refo.pdf
its about the economic systems of Haiti XI- Economic Policies and Refo.pdfits about the economic systems of Haiti XI- Economic Policies and Refo.pdf
its about the economic systems of Haiti XI- Economic Policies and Refo.pdf
 
IV- The EXT3 file system of Linux uses a multiple index structure- If (1).pdf
IV- The EXT3 file system of Linux uses a multiple index structure- If (1).pdfIV- The EXT3 file system of Linux uses a multiple index structure- If (1).pdf
IV- The EXT3 file system of Linux uses a multiple index structure- If (1).pdf
 
its about the economic systems of Haiti IX- Post-Duvalier (1986-Presen.pdf
its about the economic systems of Haiti IX- Post-Duvalier (1986-Presen.pdfits about the economic systems of Haiti IX- Post-Duvalier (1986-Presen.pdf
its about the economic systems of Haiti IX- Post-Duvalier (1986-Presen.pdf
 
Its in C++ and do not use int pls Given a string- return a new string.pdf
Its in C++ and do not use int pls Given a string- return a new string.pdfIts in C++ and do not use int pls Given a string- return a new string.pdf
Its in C++ and do not use int pls Given a string- return a new string.pdf
 
it were the total dividends paid for 2022-Maniplo Cnorce 57-84 milion.pdf
it were the total dividends paid for 2022-Maniplo Cnorce 57-84 milion.pdfit were the total dividends paid for 2022-Maniplo Cnorce 57-84 milion.pdf
it were the total dividends paid for 2022-Maniplo Cnorce 57-84 milion.pdf
 
j-51119ji-01274i- mplify the sum.pdf
j-51119ji-01274i- mplify the sum.pdfj-51119ji-01274i- mplify the sum.pdf
j-51119ji-01274i- mplify the sum.pdf
 
Ivanhoe Inc- wishes to accumulate $1-612-000 by December 31- 2035- to.pdf
Ivanhoe Inc- wishes to accumulate $1-612-000 by December 31- 2035- to.pdfIvanhoe Inc- wishes to accumulate $1-612-000 by December 31- 2035- to.pdf
Ivanhoe Inc- wishes to accumulate $1-612-000 by December 31- 2035- to.pdf
 
Jocelyn Rivers is a 68-year-old admitted for acute pulmonary edema- He.pdf
Jocelyn Rivers is a 68-year-old admitted for acute pulmonary edema- He.pdfJocelyn Rivers is a 68-year-old admitted for acute pulmonary edema- He.pdf
Jocelyn Rivers is a 68-year-old admitted for acute pulmonary edema- He.pdf
 
Joe Newbie completed a test to inspect a sample of sales invoices to v.pdf
Joe Newbie completed a test to inspect a sample of sales invoices to v.pdfJoe Newbie completed a test to inspect a sample of sales invoices to v.pdf
Joe Newbie completed a test to inspect a sample of sales invoices to v.pdf
 
Joan owns a citrus tree farm near Mesa- Arizona- Joan and her family h.pdf
Joan owns a citrus tree farm near Mesa- Arizona- Joan and her family h.pdfJoan owns a citrus tree farm near Mesa- Arizona- Joan and her family h.pdf
Joan owns a citrus tree farm near Mesa- Arizona- Joan and her family h.pdf
 
ITN 298- Capstone Project 1- Describing WAN technologies- including VP.pdf
ITN 298- Capstone Project 1- Describing WAN technologies- including VP.pdfITN 298- Capstone Project 1- Describing WAN technologies- including VP.pdf
ITN 298- Capstone Project 1- Describing WAN technologies- including VP.pdf
 
Ivanhoe Ltd- had the following account balances at December 31- 2024-P.pdf
Ivanhoe Ltd- had the following account balances at December 31- 2024-P.pdfIvanhoe Ltd- had the following account balances at December 31- 2024-P.pdf
Ivanhoe Ltd- had the following account balances at December 31- 2024-P.pdf
 
Jennifer is an older Aboriginal client- She has lived in the city all.pdf
Jennifer is an older Aboriginal client- She has lived in the city all.pdfJennifer is an older Aboriginal client- She has lived in the city all.pdf
Jennifer is an older Aboriginal client- She has lived in the city all.pdf
 
Jeff is trying very hard to change his flat tire- He struggles to lift.pdf
Jeff is trying very hard to change his flat tire- He struggles to lift.pdfJeff is trying very hard to change his flat tire- He struggles to lift.pdf
Jeff is trying very hard to change his flat tire- He struggles to lift.pdf
 
JCL Inc- is a major chip manufacturing firm that sells its products to.pdf
JCL Inc- is a major chip manufacturing firm that sells its products to.pdfJCL Inc- is a major chip manufacturing firm that sells its products to.pdf
JCL Inc- is a major chip manufacturing firm that sells its products to.pdf
 
Jenna is a flight attendant for an international carrier- In the summe.pdf
Jenna is a flight attendant for an international carrier- In the summe.pdfJenna is a flight attendant for an international carrier- In the summe.pdf
Jenna is a flight attendant for an international carrier- In the summe.pdf
 
JBL Lab 9 (Applying Best Practices for Security Logging and Monitoring.pdf
JBL Lab 9 (Applying Best Practices for Security Logging and Monitoring.pdfJBL Lab 9 (Applying Best Practices for Security Logging and Monitoring.pdf
JBL Lab 9 (Applying Best Practices for Security Logging and Monitoring.pdf
 

Recently uploaded

SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MysoreMuleSoftMeetup
 

Recently uploaded (20)

dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdfDiuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 

It's not working what am I doing wrong- Given main()- complete the Son.pdf

  • 1. It's not working what am I doing wrong? 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: the output is: import java.util.Scanner; public class Playlist { // TODO: Write method to ouptut list of songs public static void printPlaylist(SongNode songs){ SongNode song = song.getNext(); while (song != null) { song.printSongInfo(); System.out.println(); song = song.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; // Front of nodes list headNode = new SongNode(); lastNode = headNode; // Read user input until -1 entered songTitle = scnr.nextLine(); while (!songTitle.equals("-1")) { songLength = scnr.nextInt(); scnr.nextLine(); songArtist = scnr.nextLine();
  • 2. currNode = new SongNode(songTitle, songLength, songArtist); lastNode.insertAfter(currNode); lastNode = currNode; songTitle = scnr.nextLine(); } // Print linked list System.out.println("LIST OF SONGS"); System.out.println("-------------"); printPlaylist(headNode); } } public class SongNode { private String songTitle; private int songLength; private String songArtist; private SongNode nextNodeRef; // Reference to the next node public SongNode() { songTitle = ""; songLength = 0; songArtist = ""; nextNodeRef = null; } // Constructor public SongNode(String songTitleInit, int songLengthInit, String songArtistInit) { this.songTitle = songTitleInit; this.songLength = songLengthInit; this.songArtist = songArtistInit; this.nextNodeRef = null; } // Constructor public SongNode(String songTitleInit, int songLengthInit, String songArtistInit, SongNode nextLoc) { this.songTitle = songTitleInit; this.songLength = songLengthInit; this.songArtist = songArtistInit; this.nextNodeRef = nextLoc; }
  • 3. // insertAfter public void insertAfter(SongNode nodeLoc) { SongNode tmpNext; tmpNext = this.nextNodeRef; this.nextNodeRef = nodeLoc; nodeLoc.nextNodeRef = tmpNext; } // Get location pointed by nextNodeRef public SongNode getNext() { return this.nextNodeRef; } // TODO: Write printSongInfo() method public void printInfo(){ System.out.println("Title: " + songTitle); System.out.println("Length: " + songLength); System.out.println("Artist: " + songArtist); } }