SlideShare a Scribd company logo
1 of 17
Download to read offline
8.8 Program: Playlist (Java)
You will be building a linked list. Make sure to keep track of both the head and tail nodes.
(1) Create two files to submit.
SongEntry.java - Class declaration
Playlist.java - Contains main() method
Build the SongEntry class per the following specifications. Note: Some methods can initially be
method stubs (empty methods), to be completed in later steps.
Private fields
String uniqueID - Initialized to "none" in default constructor
string songName - Initialized to "none" in default constructor
string artistName - Initialized to "none" in default constructor
int songLength - Initialized to 0 in default constructor
SongEntry nextNode - Initialized to null in default constructor
Default constructor (1 pt)
Parameterized constructor (1 pt)
Public member methods
insertAfter() (1 pt)
setNext() - Mutator (1 pt)
getID() - Accessor
getSongName() - Accessor
getArtistName() - Accessor
getSongLength() - Accessor
getNext() - Accessor
printPlaylistSongs()
Ex. of printPlaylistSongs output:
(2) In main(), prompt the user for the title of the playlist. (1 pt)
Ex:
(3) Implement the printMenu() method. printMenu() takes the playlist title as a parameter and
outputs a menu of options to manipulate the playlist. Each option is represented by a single
character. Build and output the menu within the method.
If an invalid character is entered, continue to prompt for a valid choice. Hint: Implement Quit
before implementing other options. Call printMenu() in the main() method. Continue to execute
the menu until the user enters q to Quit. (3 pts)
Ex:
(4) Implement "Output full playlist" menu option. If the list is empty, output: Playlist is empty
(3 pts)
Ex:
(5) Implement the "Add song" menu item. New additions are added to the end of the list. (2
pts)
Ex:
(6) Implement the "Remove song" method. Prompt the user for the unique ID of the song to be
removed.(4 pts)
Ex:
(7) Implement the "Change position of song" menu option. Prompt the user for the current
position of the song and the desired new position. Valid new positions are 1 - n (the number of
nodes). If the user enters a new position that is less than 1, move the node to the position 1 (the
head). If the user enters a new position greater than n, move the node to position n (the tail). 6
cases will be tested:
Moving the head node (1 pt)
Moving the tail node (1 pt)
Moving a node to the head (1 pt)
Moving a node to the tail (1 pt)
Moving a node up the list (1 pt)
Moving a node down the list (1 pt)
Ex:
(8) Implement the "Output songs by specific artist" menu option. Prompt the user for the
artist's name, and output the node's information, starting with the node's current position. (2 pt)
Ex:
(9) Implement the "Output total time of playlist" menu option. Output the sum of the time of
the playlist's songs (in seconds). (2 pts)
Ex:
Solution
SongEntry.java
package playlist;
public class SongEntry {
private String uniqueID;
private String songName;
private String artistName;
private int songLength;
SongEntry nextNode;
SongEntry()
{
uniqueID = "";
songName = "";
artistName = "";
songLength = 0;
nextNode = null;
}
SongEntry(String uniqueID, String songName, String artistName, int songLength)
{
this.uniqueID = uniqueID;
this.songName = songName;
this.songLength = songLength;
this.artistName = artistName;
this.nextNode = null;
}
public void insertAfter( SongEntry entry)
{
SongEntry entries = this;
while(entries.nextNode != null)
{
entries = entries.nextNode;
}
entries.nextNode = entry;
}
public void setNext(SongEntry entry){
this.nextNode = entry;
}
public String getID()
{
return this.uniqueID;
}
public String getSongName()
{
return this.songName;
}
public String getArtistName()
{
return this.artistName;
}
public int getSongLength()
{
return this.songLength;
}
public SongEntry getNext()
{
return this.nextNode;
}
public void printPlaylistSongs()
{
System.out.println("Unique ID: "+getID());
System.out.println("Song Name: "+getSongName());
System.out.println("Artist Name: "+getArtistName());
System.out.println("Song Length(in seconds): "+getSongLength());
}
}
Playlist.java
package playlist;
import java.util.Scanner;
public class Playlist {
public static Scanner sc = new Scanner(System.in);
public static Scanner scInt = new Scanner(System.in);
public static SongEntry headSong = new SongEntry();
public static SongEntry tailSong = new SongEntry();
public static SongEntry allEntries;
public static int numberOfNodes = 0;
public static void printMenu(String playlistTitle)
{
System.out.println(" "+playlistTitle.toUpperCase()+" PLAYLIST MENU");
System.out.println("a - Add song d - Remove song c - Change position of song s - Output
songs by specific artist");
System.out.println("t - Output total time of playlist (in seconds) o - Output full playlist q -
Quit");
System.out.println(" Choose an option: ");
String option = sc.next();
boolean isEnter = option.equals("a") || option.equals("d") || option.equals("c") ||
option.equals("s") || option.equals("t") || option.equals("o") || option.equals("q");
if(isEnter)
{
switch(option.charAt(0))
{
case 'a': addSong();
printMenu(playlistTitle);
break;
case 'd': allEntries = removeSong(allEntries);
printMenu(playlistTitle);
break;
case 'c': allEntries = changeSongPosition(allEntries);
printMenu(playlistTitle);
break;
case 's': songsBySpecificArtist(allEntries);
printMenu(playlistTitle);
break;
case 't': totalTimeofPlaylist(allEntries);
printMenu(playlistTitle);
break;
case 'o': outputFullPlaylist(allEntries);
printMenu(playlistTitle);
break;
case 'q': break;
}
}
else
{
System.out.println("Invalid Choice !");
printMenu(playlistTitle);
}
}
public static void outputFullPlaylist(SongEntry entries)
{
int counter = 1;
if(entries != null)
{
System.out.println(counter+".");
entries.printPlaylistSongs(); // head node
counter++;
while(entries.nextNode != null) // all the remaining nodes
{
entries = entries.nextNode;
System.out.println(counter+".");
entries.printPlaylistSongs();
counter++;
}
}
else
{
System.out.println("Playlist is empty");
}
}
public static void addSong()
{
sc = new Scanner(System.in);
System.out.println("ADD SONG");
System.out.println("Enter song's Unique ID: ");
String songID = sc.next();
sc = new Scanner(System.in);
System.out.println("Enter song's name: ");
String songname = sc.nextLine();
sc = new Scanner(System.in);
System.out.println("Enter artist's name: ");
String artistName = sc.nextLine();
System.out.println("Enter song's length(in seconds): ");
int songlength = scInt.nextInt();
SongEntry entry = new SongEntry(songID, songname, artistName, songlength);
if(allEntries == null)
{
headSong = entry; // this is the head
allEntries = entry;
tailSong = entry; // this is the tail
numberOfNodes++;
}
else
{
allEntries.insertAfter(entry);
tailSong = entry;
numberOfNodes++;
}
}
public static SongEntry removeSong(SongEntry entries)
{
System.out.println("Enter the song's unique ID: ");
String id = sc.next();
SongEntry newEntry = null, entry=null;
int counter = 0;
while(entries != null)
{
if(counter!=0)
{
newEntry.nextNode = null;
newEntry = newEntry.nextNode;
}
if(!entries.getID().equals(id))
{
newEntry = new SongEntry();
newEntry.setUniqueID(entries.getID());
newEntry.setSongName(entries.getSongName());
newEntry.setArtistName(entries.getArtistName());
newEntry.setSongLength(entries.getSongLength());
if(entry == null)
entry = newEntry;
else
entry.insertAfter(newEntry);
counter++;
}
else
{
System.out.println(entries.getSongName()+" removed");
numberOfNodes--;
}
entries = entries.nextNode;
}
return entry;
}
public static SongEntry changeSongPosition(SongEntry entries)
{
System.out.println("CHANGE POSITION OF SONG");
System.out.println("ENTER song's current position: ");
int currentPos = scInt.nextInt();
System.out.println("Enter new position of song: ");
int newPos = scInt.nextInt();
SongEntry currentPosEntry = null, entry = null, newPosEntry = null, returnEntry = null;
entry = entries;
int counter = 1;
// System.out.println("Number of nodes: " + numberOfNodes);
if(newPos<1)
newPos = 1;
else if(newPos>numberOfNodes)
newPos = numberOfNodes;
System.out.println("cuurent pos: "+currentPos);
System.out.println("new pos: "+newPos);
for(int i=1; i<=numberOfNodes; i++)
{
if(i==currentPos)
currentPosEntry = entries;
else if(i==newPos)
newPosEntry = entries;
else
entries = entries.nextNode;
}
// System.out.println("After for loop");
//System.out.println("Current song details" ); currentPosEntry.printPlaylistSongs();
// System.out.println("New song details"); newPosEntry.printPlaylistSongs();
entries = entry;
while(counter <= numberOfNodes+1)
{
if(counter == currentPos) // we need to adjust the current position
{
entries = entries.nextNode;
if(entries !=null)
{
entry = new SongEntry(entries.getID(), entries.getSongName(), entries.getArtistName(),
entries.getSongLength());
if(returnEntry == null)
returnEntry = entry;
else
returnEntry.insertAfter(entry);
entries = entries.nextNode;
}
counter++;
}
else if(counter == newPos)
{
entry = currentPosEntry;
entry.nextNode = null;
if(returnEntry == null)
returnEntry = entry;
else
returnEntry.insertAfter(entry);
counter++;
}
else
{
if(entries !=null)
{
entry = new SongEntry(entries.getID(), entries.getSongName(), entries.getArtistName(),
entries.getSongLength());
if(returnEntry == null)
returnEntry = entry;
else
returnEntry.insertAfter(entry);
entries = entries.nextNode;
}
counter++;
}
}
return returnEntry;
}
public static void totalTimeofPlaylist(SongEntry entries)
{
System.out.println("OUTPUT TOTAL TIME OF PLAYLIST (IN SECONDS)");
int totalSeconds = entries.getSongLength();
entries = entries.nextNode;
while(entries != null)
{
totalSeconds += entries.getSongLength();
entries = entries.nextNode;
}
System.out.println("Total Time: "+totalSeconds+" seconds");
}
public static void songsBySpecificArtist(SongEntry entries)
{
sc = new Scanner(System.in);
System.out.println("OUTPUT SONGS BY SPECIFIC ARTIST");
System.out.println("Enter artist's name: ");
String artistname = sc.nextLine();
while(entries != null)
{
if(entries.getArtistName().equals(artistname))
{
entries.printPlaylistSongs();
}
entries = entries.nextNode;
}
}
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Enter playlist's title: ");
sc = new Scanner(System.in);
String title = sc.nextLine();
printMenu(title);
}
}
OUTPUT:
Enter playlist's title:
jem
JEM PLAYLIST MENU
a - Add song
d - Remove song
c - Change position of song
s - Output songs by specific artist
t - Output total time of playlist (in seconds)
o - Output full playlist
q - Quit
Choose an option:
a
ADD SONG
Enter song's Unique ID:
s1
Enter song's name:
All for you
Enter artist's name:
Minda
Enter song's length(in seconds):
234
JEM PLAYLIST MENU
a - Add song
d - Remove song
c - Change position of song
s - Output songs by specific artist
t - Output total time of playlist (in seconds)
o - Output full playlist
q - Quit
Choose an option:
a
ADD SONG
Enter song's Unique ID:
s2
Enter song's name:
good for you
Enter artist's name:
selena gomez
Enter song's length(in seconds):
233
JEM PLAYLIST MENU
a - Add song
d - Remove song
c - Change position of song
s - Output songs by specific artist
t - Output total time of playlist (in seconds)
o - Output full playlist
q - Quit
Choose an option:
d
Enter the song's unique ID:
s1
All for you removed
JEM PLAYLIST MENU
a - Add song
d - Remove song
c - Change position of song
s - Output songs by specific artist
t - Output total time of playlist (in seconds)
o - Output full playlist
q - Quit
Choose an option:
o
1.
Unique ID: s2
Song Name: good for you
Artist Name: selena gomez
Song Length(in seconds): 233
JEM PLAYLIST MENU
a - Add song
d - Remove song
c - Change position of song
s - Output songs by specific artist
t - Output total time of playlist (in seconds)
o - Output full playlist
q - Quit
Choose an option:
t
OUTPUT TOTAL TIME OF PLAYLIST (IN SECONDS)
Total Time: 233 seconds
JEM PLAYLIST MENU
a - Add song
d - Remove song
c - Change position of song
s - Output songs by specific artist
t - Output total time of playlist (in seconds)
o - Output full playlist
q - Quit
Choose an option:
a
ADD SONG
Enter song's Unique ID:
s3
Enter song's name:
baby
Enter artist's name:
justin beiber
Enter song's length(in seconds):
221
JEM PLAYLIST MENU
a - Add song
d - Remove song
c - Change position of song
s - Output songs by specific artist
t - Output total time of playlist (in seconds)
o - Output full playlist
q - Quit
Choose an option:
s
OUTPUT SONGS BY SPECIFIC ARTIST
Enter artist's name:
selena gomez
Unique ID: s2
Song Name: good for you
Artist Name: selena gomez
Song Length(in seconds): 233
JEM PLAYLIST MENU
a - Add song
d - Remove song
c - Change position of song
s - Output songs by specific artist
t - Output total time of playlist (in seconds)
o - Output full playlist
q - Quit
Choose an option:
c
CHANGE POSITION OF SONG
ENTER song's current position:
1
Enter new position of song:
2
cuurent pos: 1
new pos: 2
JEM PLAYLIST MENU
a - Add song
d - Remove song
c - Change position of song
s - Output songs by specific artist
t - Output total time of playlist (in seconds)
o - Output full playlist
q - Quit
Choose an option:
o
1.
Unique ID: s3
Song Name: baby
Artist Name: justin beiber
Song Length(in seconds): 221
2.
Unique ID: s2
Song Name: good for you
Artist Name: selena gomez
Song Length(in seconds): 233
JEM PLAYLIST MENU
a - Add song
d - Remove song
c - Change position of song
s - Output songs by specific artist
t - Output total time of playlist (in seconds)
o - Output full playlist
q - Quit
Choose an option: q

More Related Content

Similar to 8.8 Program Playlist (Java)You will be building a linked list. Ma.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.pdfaddtechglobalmarketi
 
I need help writing test Codepackage org.example;import j.pdf
I need help writing test Codepackage org.example;import j.pdfI need help writing test Codepackage org.example;import j.pdf
I need help writing test Codepackage org.example;import j.pdfmail931892
 
Can someone please help me complete the add_song function .pdf
Can someone please help me complete the add_song function .pdfCan someone please help me complete the add_song function .pdf
Can someone please help me complete the add_song function .pdfakshpatil4
 
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 .pdfakshpatil4
 
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.pdfarihanthtextiles
 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfmail931892
 
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. .pdfdbrienmhompsonkath75
 
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.pdficonsystemsslm
 
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.pdfaddtechglobalmarketi
 
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.pdfprajeetjain
 
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 .pdffazanmobiles
 
1817 LAB Playlist output linked list Given main compl.pdf
1817 LAB Playlist output linked list Given main compl.pdf1817 LAB Playlist output linked list Given main compl.pdf
1817 LAB Playlist output linked list Given main compl.pdfspshotham
 
Given main(), complete the SongNode class to include the printSong.pdf
Given main(), complete the SongNode class to include the printSong.pdfGiven main(), complete the SongNode class to include the printSong.pdf
Given main(), complete the SongNode class to include the printSong.pdfillyasraja7
 
You are required to implement all the classes as specified by UML di.pdf
You are required to implement all the classes as specified by UML di.pdfYou are required to implement all the classes as specified by UML di.pdf
You are required to implement all the classes as specified by UML di.pdfarorasales234
 
Problem 2 struct to hold information about a song struct So.pdf
 Problem 2 struct to hold information about a song struct So.pdf Problem 2 struct to hold information about a song struct So.pdf
Problem 2 struct to hold information about a song struct So.pdfahujaelectronics175
 
In C++ Plz LAB- Playlist (output linked list) Given main()- complete.pdf
In C++ Plz  LAB- Playlist (output linked list) Given main()- complete.pdfIn C++ Plz  LAB- Playlist (output linked list) Given main()- complete.pdf
In C++ Plz LAB- Playlist (output linked list) Given main()- complete.pdfshreeaadithyaacellso
 
#include sstream #include linkylist.h #include iostream.pdf
#include sstream #include linkylist.h #include iostream.pdf#include sstream #include linkylist.h #include iostream.pdf
#include sstream #include linkylist.h #include iostream.pdfaravlitraders2012
 
In C++ Plz and In What Order Do I Put It In- LAB- Playlist (output li.pdf
In C++ Plz and In What Order Do I Put It In-  LAB- Playlist (output li.pdfIn C++ Plz and In What Order Do I Put It In-  LAB- Playlist (output li.pdf
In C++ Plz and In What Order Do I Put It In- LAB- Playlist (output li.pdfshreeaadithyaacellso
 
Please change this method to recursive method.  public String post.pdf
Please change this method to recursive method.  public String post.pdfPlease change this method to recursive method.  public String post.pdf
Please change this method to recursive method.  public String post.pdfpallavi953613
 

Similar to 8.8 Program Playlist (Java)You will be building a linked list. Ma.pdf (20)

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 test Codepackage org.example;import j.pdf
I need help writing test Codepackage org.example;import j.pdfI need help writing test Codepackage org.example;import j.pdf
I need help writing test Codepackage org.example;import j.pdf
 
Can someone please help me complete the add_song function .pdf
Can someone please help me complete the add_song function .pdfCan someone please help me complete the add_song function .pdf
Can someone please help me complete the add_song function .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
 
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
 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.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
 
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
 
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
 
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
 
1817 LAB Playlist output linked list Given main compl.pdf
1817 LAB Playlist output linked list Given main compl.pdf1817 LAB Playlist output linked list Given main compl.pdf
1817 LAB Playlist output linked list Given main compl.pdf
 
Given main(), complete the SongNode class to include the printSong.pdf
Given main(), complete the SongNode class to include the printSong.pdfGiven main(), complete the SongNode class to include the printSong.pdf
Given main(), complete the SongNode class to include the printSong.pdf
 
You are required to implement all the classes as specified by UML di.pdf
You are required to implement all the classes as specified by UML di.pdfYou are required to implement all the classes as specified by UML di.pdf
You are required to implement all the classes as specified by UML di.pdf
 
Problem 2 struct to hold information about a song struct So.pdf
 Problem 2 struct to hold information about a song struct So.pdf Problem 2 struct to hold information about a song struct So.pdf
Problem 2 struct to hold information about a song struct So.pdf
 
In C++ Plz LAB- Playlist (output linked list) Given main()- complete.pdf
In C++ Plz  LAB- Playlist (output linked list) Given main()- complete.pdfIn C++ Plz  LAB- Playlist (output linked list) Given main()- complete.pdf
In C++ Plz LAB- Playlist (output linked list) Given main()- complete.pdf
 
#include sstream #include linkylist.h #include iostream.pdf
#include sstream #include linkylist.h #include iostream.pdf#include sstream #include linkylist.h #include iostream.pdf
#include sstream #include linkylist.h #include iostream.pdf
 
In C++ Plz and In What Order Do I Put It In- LAB- Playlist (output li.pdf
In C++ Plz and In What Order Do I Put It In-  LAB- Playlist (output li.pdfIn C++ Plz and In What Order Do I Put It In-  LAB- Playlist (output li.pdf
In C++ Plz and In What Order Do I Put It In- LAB- Playlist (output li.pdf
 
JSON By Example
JSON By ExampleJSON By Example
JSON By Example
 
Please change this method to recursive method.  public String post.pdf
Please change this method to recursive method.  public String post.pdfPlease change this method to recursive method.  public String post.pdf
Please change this method to recursive method.  public String post.pdf
 

More from ARCHANASTOREKOTA

Please help! Computer Science C++ programming code needed.Thank yo.pdf
Please help! Computer Science C++ programming code needed.Thank yo.pdfPlease help! Computer Science C++ programming code needed.Thank yo.pdf
Please help! Computer Science C++ programming code needed.Thank yo.pdfARCHANASTOREKOTA
 
Please Answer, will rate! Exercise 1 - Classifying financial stateme.pdf
Please Answer, will rate! Exercise 1 - Classifying financial stateme.pdfPlease Answer, will rate! Exercise 1 - Classifying financial stateme.pdf
Please Answer, will rate! Exercise 1 - Classifying financial stateme.pdfARCHANASTOREKOTA
 
Need 2 -3 paragraphConsidering the aesthetics of the late 19th cen.pdf
Need 2 -3 paragraphConsidering the aesthetics of the late 19th cen.pdfNeed 2 -3 paragraphConsidering the aesthetics of the late 19th cen.pdf
Need 2 -3 paragraphConsidering the aesthetics of the late 19th cen.pdfARCHANASTOREKOTA
 
Match each statement to the most appropriate choices. More than one .pdf
Match each statement to the most appropriate choices. More than one .pdfMatch each statement to the most appropriate choices. More than one .pdf
Match each statement to the most appropriate choices. More than one .pdfARCHANASTOREKOTA
 
List three sources of variability in material properties. If that va.pdf
List three sources of variability in material properties. If that va.pdfList three sources of variability in material properties. If that va.pdf
List three sources of variability in material properties. If that va.pdfARCHANASTOREKOTA
 
Need the fill in the blank questions answeredSolution1) CamboB.pdf
Need the fill in the blank questions answeredSolution1) CamboB.pdfNeed the fill in the blank questions answeredSolution1) CamboB.pdf
Need the fill in the blank questions answeredSolution1) CamboB.pdfARCHANASTOREKOTA
 
making and testing a prediction suppose that after 22 months, gupp.pdf
making and testing a prediction suppose that after 22 months, gupp.pdfmaking and testing a prediction suppose that after 22 months, gupp.pdf
making and testing a prediction suppose that after 22 months, gupp.pdfARCHANASTOREKOTA
 
Life is wholly dependent on water. List and discuss two reasons why .pdf
Life is wholly dependent on water. List and discuss two reasons why .pdfLife is wholly dependent on water. List and discuss two reasons why .pdf
Life is wholly dependent on water. List and discuss two reasons why .pdfARCHANASTOREKOTA
 
John Rawls argued that societys goal should be to lessen the welfar.pdf
John Rawls argued that societys goal should be to lessen the welfar.pdfJohn Rawls argued that societys goal should be to lessen the welfar.pdf
John Rawls argued that societys goal should be to lessen the welfar.pdfARCHANASTOREKOTA
 
In Exercises 19-24, find the volume of the solid generated by revolvi.pdf
In Exercises 19-24, find the volume of the solid generated by revolvi.pdfIn Exercises 19-24, find the volume of the solid generated by revolvi.pdf
In Exercises 19-24, find the volume of the solid generated by revolvi.pdfARCHANASTOREKOTA
 
In which step of meiosis, the members of tetra separate Solutio.pdf
In which step of meiosis, the members of tetra separate  Solutio.pdfIn which step of meiosis, the members of tetra separate  Solutio.pdf
In which step of meiosis, the members of tetra separate Solutio.pdfARCHANASTOREKOTA
 
Identify the distinguishing characteristics of member of Phylum Cnid.pdf
Identify the distinguishing characteristics of member of Phylum Cnid.pdfIdentify the distinguishing characteristics of member of Phylum Cnid.pdf
Identify the distinguishing characteristics of member of Phylum Cnid.pdfARCHANASTOREKOTA
 
If most evolutionary change occurs during and immediately after spec.pdf
If most evolutionary change occurs during and immediately after spec.pdfIf most evolutionary change occurs during and immediately after spec.pdf
If most evolutionary change occurs during and immediately after spec.pdfARCHANASTOREKOTA
 
Imagine that someone picking up roses in a garden gets a scratch fro.pdf
Imagine that someone picking up roses in a garden gets a scratch fro.pdfImagine that someone picking up roses in a garden gets a scratch fro.pdf
Imagine that someone picking up roses in a garden gets a scratch fro.pdfARCHANASTOREKOTA
 
I need help working out this question . woman has normal vision al.pdf
I need help working out this question . woman has normal vision al.pdfI need help working out this question . woman has normal vision al.pdf
I need help working out this question . woman has normal vision al.pdfARCHANASTOREKOTA
 
I have a Programming is Binary Tree Search (BTS) for strings with po.pdf
I have a Programming is Binary Tree Search (BTS) for strings with po.pdfI have a Programming is Binary Tree Search (BTS) for strings with po.pdf
I have a Programming is Binary Tree Search (BTS) for strings with po.pdfARCHANASTOREKOTA
 
How is ATP produced in mammalian cells under aerobic conditions1..pdf
How is ATP produced in mammalian cells under aerobic conditions1..pdfHow is ATP produced in mammalian cells under aerobic conditions1..pdf
How is ATP produced in mammalian cells under aerobic conditions1..pdfARCHANASTOREKOTA
 
How con osmosis work for and against homeostasis How do osmosis .pdf
How con osmosis work for and against homeostasis How do osmosis .pdfHow con osmosis work for and against homeostasis How do osmosis .pdf
How con osmosis work for and against homeostasis How do osmosis .pdfARCHANASTOREKOTA
 
Enzymes and KE. Whats the relationship in terms of substrate mo.pdf
Enzymes and KE. Whats the relationship in terms of substrate mo.pdfEnzymes and KE. Whats the relationship in terms of substrate mo.pdf
Enzymes and KE. Whats the relationship in terms of substrate mo.pdfARCHANASTOREKOTA
 
Explain membranes. Include the definition and name the four types an.pdf
Explain membranes. Include the definition and name the four types an.pdfExplain membranes. Include the definition and name the four types an.pdf
Explain membranes. Include the definition and name the four types an.pdfARCHANASTOREKOTA
 

More from ARCHANASTOREKOTA (20)

Please help! Computer Science C++ programming code needed.Thank yo.pdf
Please help! Computer Science C++ programming code needed.Thank yo.pdfPlease help! Computer Science C++ programming code needed.Thank yo.pdf
Please help! Computer Science C++ programming code needed.Thank yo.pdf
 
Please Answer, will rate! Exercise 1 - Classifying financial stateme.pdf
Please Answer, will rate! Exercise 1 - Classifying financial stateme.pdfPlease Answer, will rate! Exercise 1 - Classifying financial stateme.pdf
Please Answer, will rate! Exercise 1 - Classifying financial stateme.pdf
 
Need 2 -3 paragraphConsidering the aesthetics of the late 19th cen.pdf
Need 2 -3 paragraphConsidering the aesthetics of the late 19th cen.pdfNeed 2 -3 paragraphConsidering the aesthetics of the late 19th cen.pdf
Need 2 -3 paragraphConsidering the aesthetics of the late 19th cen.pdf
 
Match each statement to the most appropriate choices. More than one .pdf
Match each statement to the most appropriate choices. More than one .pdfMatch each statement to the most appropriate choices. More than one .pdf
Match each statement to the most appropriate choices. More than one .pdf
 
List three sources of variability in material properties. If that va.pdf
List three sources of variability in material properties. If that va.pdfList three sources of variability in material properties. If that va.pdf
List three sources of variability in material properties. If that va.pdf
 
Need the fill in the blank questions answeredSolution1) CamboB.pdf
Need the fill in the blank questions answeredSolution1) CamboB.pdfNeed the fill in the blank questions answeredSolution1) CamboB.pdf
Need the fill in the blank questions answeredSolution1) CamboB.pdf
 
making and testing a prediction suppose that after 22 months, gupp.pdf
making and testing a prediction suppose that after 22 months, gupp.pdfmaking and testing a prediction suppose that after 22 months, gupp.pdf
making and testing a prediction suppose that after 22 months, gupp.pdf
 
Life is wholly dependent on water. List and discuss two reasons why .pdf
Life is wholly dependent on water. List and discuss two reasons why .pdfLife is wholly dependent on water. List and discuss two reasons why .pdf
Life is wholly dependent on water. List and discuss two reasons why .pdf
 
John Rawls argued that societys goal should be to lessen the welfar.pdf
John Rawls argued that societys goal should be to lessen the welfar.pdfJohn Rawls argued that societys goal should be to lessen the welfar.pdf
John Rawls argued that societys goal should be to lessen the welfar.pdf
 
In Exercises 19-24, find the volume of the solid generated by revolvi.pdf
In Exercises 19-24, find the volume of the solid generated by revolvi.pdfIn Exercises 19-24, find the volume of the solid generated by revolvi.pdf
In Exercises 19-24, find the volume of the solid generated by revolvi.pdf
 
In which step of meiosis, the members of tetra separate Solutio.pdf
In which step of meiosis, the members of tetra separate  Solutio.pdfIn which step of meiosis, the members of tetra separate  Solutio.pdf
In which step of meiosis, the members of tetra separate Solutio.pdf
 
Identify the distinguishing characteristics of member of Phylum Cnid.pdf
Identify the distinguishing characteristics of member of Phylum Cnid.pdfIdentify the distinguishing characteristics of member of Phylum Cnid.pdf
Identify the distinguishing characteristics of member of Phylum Cnid.pdf
 
If most evolutionary change occurs during and immediately after spec.pdf
If most evolutionary change occurs during and immediately after spec.pdfIf most evolutionary change occurs during and immediately after spec.pdf
If most evolutionary change occurs during and immediately after spec.pdf
 
Imagine that someone picking up roses in a garden gets a scratch fro.pdf
Imagine that someone picking up roses in a garden gets a scratch fro.pdfImagine that someone picking up roses in a garden gets a scratch fro.pdf
Imagine that someone picking up roses in a garden gets a scratch fro.pdf
 
I need help working out this question . woman has normal vision al.pdf
I need help working out this question . woman has normal vision al.pdfI need help working out this question . woman has normal vision al.pdf
I need help working out this question . woman has normal vision al.pdf
 
I have a Programming is Binary Tree Search (BTS) for strings with po.pdf
I have a Programming is Binary Tree Search (BTS) for strings with po.pdfI have a Programming is Binary Tree Search (BTS) for strings with po.pdf
I have a Programming is Binary Tree Search (BTS) for strings with po.pdf
 
How is ATP produced in mammalian cells under aerobic conditions1..pdf
How is ATP produced in mammalian cells under aerobic conditions1..pdfHow is ATP produced in mammalian cells under aerobic conditions1..pdf
How is ATP produced in mammalian cells under aerobic conditions1..pdf
 
How con osmosis work for and against homeostasis How do osmosis .pdf
How con osmosis work for and against homeostasis How do osmosis .pdfHow con osmosis work for and against homeostasis How do osmosis .pdf
How con osmosis work for and against homeostasis How do osmosis .pdf
 
Enzymes and KE. Whats the relationship in terms of substrate mo.pdf
Enzymes and KE. Whats the relationship in terms of substrate mo.pdfEnzymes and KE. Whats the relationship in terms of substrate mo.pdf
Enzymes and KE. Whats the relationship in terms of substrate mo.pdf
 
Explain membranes. Include the definition and name the four types an.pdf
Explain membranes. Include the definition and name the four types an.pdfExplain membranes. Include the definition and name the four types an.pdf
Explain membranes. Include the definition and name the four types an.pdf
 

Recently uploaded

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 

Recently uploaded (20)

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 

8.8 Program Playlist (Java)You will be building a linked list. Ma.pdf

  • 1. 8.8 Program: Playlist (Java) You will be building a linked list. Make sure to keep track of both the head and tail nodes. (1) Create two files to submit. SongEntry.java - Class declaration Playlist.java - Contains main() method Build the SongEntry class per the following specifications. Note: Some methods can initially be method stubs (empty methods), to be completed in later steps. Private fields String uniqueID - Initialized to "none" in default constructor string songName - Initialized to "none" in default constructor string artistName - Initialized to "none" in default constructor int songLength - Initialized to 0 in default constructor SongEntry nextNode - Initialized to null in default constructor Default constructor (1 pt) Parameterized constructor (1 pt) Public member methods insertAfter() (1 pt) setNext() - Mutator (1 pt) getID() - Accessor getSongName() - Accessor getArtistName() - Accessor getSongLength() - Accessor getNext() - Accessor printPlaylistSongs() Ex. of printPlaylistSongs output: (2) In main(), prompt the user for the title of the playlist. (1 pt) Ex: (3) Implement the printMenu() method. printMenu() takes the playlist title as a parameter and outputs a menu of options to manipulate the playlist. Each option is represented by a single character. Build and output the menu within the method. If an invalid character is entered, continue to prompt for a valid choice. Hint: Implement Quit before implementing other options. Call printMenu() in the main() method. Continue to execute the menu until the user enters q to Quit. (3 pts)
  • 2. Ex: (4) Implement "Output full playlist" menu option. If the list is empty, output: Playlist is empty (3 pts) Ex: (5) Implement the "Add song" menu item. New additions are added to the end of the list. (2 pts) Ex: (6) Implement the "Remove song" method. Prompt the user for the unique ID of the song to be removed.(4 pts) Ex: (7) Implement the "Change position of song" menu option. Prompt the user for the current position of the song and the desired new position. Valid new positions are 1 - n (the number of nodes). If the user enters a new position that is less than 1, move the node to the position 1 (the head). If the user enters a new position greater than n, move the node to position n (the tail). 6 cases will be tested: Moving the head node (1 pt) Moving the tail node (1 pt) Moving a node to the head (1 pt) Moving a node to the tail (1 pt) Moving a node up the list (1 pt) Moving a node down the list (1 pt) Ex: (8) Implement the "Output songs by specific artist" menu option. Prompt the user for the artist's name, and output the node's information, starting with the node's current position. (2 pt) Ex:
  • 3. (9) Implement the "Output total time of playlist" menu option. Output the sum of the time of the playlist's songs (in seconds). (2 pts) Ex: Solution SongEntry.java package playlist; public class SongEntry { private String uniqueID; private String songName; private String artistName; private int songLength; SongEntry nextNode; SongEntry() { uniqueID = ""; songName = ""; artistName = ""; songLength = 0; nextNode = null; } SongEntry(String uniqueID, String songName, String artistName, int songLength) { this.uniqueID = uniqueID; this.songName = songName; this.songLength = songLength; this.artistName = artistName; this.nextNode = null; } public void insertAfter( SongEntry entry)
  • 4. { SongEntry entries = this; while(entries.nextNode != null) { entries = entries.nextNode; } entries.nextNode = entry; } public void setNext(SongEntry entry){ this.nextNode = entry; } public String getID() { return this.uniqueID; } public String getSongName() { return this.songName; } public String getArtistName() { return this.artistName; } public int getSongLength() { return this.songLength; } public SongEntry getNext() { return this.nextNode;
  • 5. } public void printPlaylistSongs() { System.out.println("Unique ID: "+getID()); System.out.println("Song Name: "+getSongName()); System.out.println("Artist Name: "+getArtistName()); System.out.println("Song Length(in seconds): "+getSongLength()); } } Playlist.java package playlist; import java.util.Scanner; public class Playlist { public static Scanner sc = new Scanner(System.in); public static Scanner scInt = new Scanner(System.in); public static SongEntry headSong = new SongEntry(); public static SongEntry tailSong = new SongEntry(); public static SongEntry allEntries; public static int numberOfNodes = 0; public static void printMenu(String playlistTitle) { System.out.println(" "+playlistTitle.toUpperCase()+" PLAYLIST MENU"); System.out.println("a - Add song d - Remove song c - Change position of song s - Output songs by specific artist"); System.out.println("t - Output total time of playlist (in seconds) o - Output full playlist q - Quit"); System.out.println(" Choose an option: "); String option = sc.next(); boolean isEnter = option.equals("a") || option.equals("d") || option.equals("c") || option.equals("s") || option.equals("t") || option.equals("o") || option.equals("q"); if(isEnter) { switch(option.charAt(0))
  • 6. { case 'a': addSong(); printMenu(playlistTitle); break; case 'd': allEntries = removeSong(allEntries); printMenu(playlistTitle); break; case 'c': allEntries = changeSongPosition(allEntries); printMenu(playlistTitle); break; case 's': songsBySpecificArtist(allEntries); printMenu(playlistTitle); break; case 't': totalTimeofPlaylist(allEntries); printMenu(playlistTitle); break; case 'o': outputFullPlaylist(allEntries); printMenu(playlistTitle); break; case 'q': break; } } else { System.out.println("Invalid Choice !"); printMenu(playlistTitle); } }
  • 7. public static void outputFullPlaylist(SongEntry entries) { int counter = 1; if(entries != null) { System.out.println(counter+"."); entries.printPlaylistSongs(); // head node counter++; while(entries.nextNode != null) // all the remaining nodes { entries = entries.nextNode; System.out.println(counter+"."); entries.printPlaylistSongs(); counter++; } } else { System.out.println("Playlist is empty"); } } public static void addSong() { sc = new Scanner(System.in); System.out.println("ADD SONG"); System.out.println("Enter song's Unique ID: "); String songID = sc.next(); sc = new Scanner(System.in); System.out.println("Enter song's name: "); String songname = sc.nextLine(); sc = new Scanner(System.in); System.out.println("Enter artist's name: "); String artistName = sc.nextLine(); System.out.println("Enter song's length(in seconds): "); int songlength = scInt.nextInt();
  • 8. SongEntry entry = new SongEntry(songID, songname, artistName, songlength); if(allEntries == null) { headSong = entry; // this is the head allEntries = entry; tailSong = entry; // this is the tail numberOfNodes++; } else { allEntries.insertAfter(entry); tailSong = entry; numberOfNodes++; } } public static SongEntry removeSong(SongEntry entries) { System.out.println("Enter the song's unique ID: "); String id = sc.next(); SongEntry newEntry = null, entry=null; int counter = 0; while(entries != null) { if(counter!=0) { newEntry.nextNode = null; newEntry = newEntry.nextNode; } if(!entries.getID().equals(id)) { newEntry = new SongEntry(); newEntry.setUniqueID(entries.getID()); newEntry.setSongName(entries.getSongName());
  • 9. newEntry.setArtistName(entries.getArtistName()); newEntry.setSongLength(entries.getSongLength()); if(entry == null) entry = newEntry; else entry.insertAfter(newEntry); counter++; } else { System.out.println(entries.getSongName()+" removed"); numberOfNodes--; } entries = entries.nextNode; } return entry; } public static SongEntry changeSongPosition(SongEntry entries) { System.out.println("CHANGE POSITION OF SONG"); System.out.println("ENTER song's current position: "); int currentPos = scInt.nextInt(); System.out.println("Enter new position of song: "); int newPos = scInt.nextInt(); SongEntry currentPosEntry = null, entry = null, newPosEntry = null, returnEntry = null; entry = entries; int counter = 1; // System.out.println("Number of nodes: " + numberOfNodes); if(newPos<1) newPos = 1; else if(newPos>numberOfNodes) newPos = numberOfNodes; System.out.println("cuurent pos: "+currentPos); System.out.println("new pos: "+newPos);
  • 10. for(int i=1; i<=numberOfNodes; i++) { if(i==currentPos) currentPosEntry = entries; else if(i==newPos) newPosEntry = entries; else entries = entries.nextNode; } // System.out.println("After for loop"); //System.out.println("Current song details" ); currentPosEntry.printPlaylistSongs(); // System.out.println("New song details"); newPosEntry.printPlaylistSongs(); entries = entry; while(counter <= numberOfNodes+1) { if(counter == currentPos) // we need to adjust the current position { entries = entries.nextNode; if(entries !=null) { entry = new SongEntry(entries.getID(), entries.getSongName(), entries.getArtistName(), entries.getSongLength()); if(returnEntry == null) returnEntry = entry; else returnEntry.insertAfter(entry); entries = entries.nextNode; } counter++; } else if(counter == newPos) { entry = currentPosEntry; entry.nextNode = null;
  • 11. if(returnEntry == null) returnEntry = entry; else returnEntry.insertAfter(entry); counter++; } else { if(entries !=null) { entry = new SongEntry(entries.getID(), entries.getSongName(), entries.getArtistName(), entries.getSongLength()); if(returnEntry == null) returnEntry = entry; else returnEntry.insertAfter(entry); entries = entries.nextNode; } counter++; } } return returnEntry; } public static void totalTimeofPlaylist(SongEntry entries) { System.out.println("OUTPUT TOTAL TIME OF PLAYLIST (IN SECONDS)"); int totalSeconds = entries.getSongLength(); entries = entries.nextNode; while(entries != null) { totalSeconds += entries.getSongLength(); entries = entries.nextNode; }
  • 12. System.out.println("Total Time: "+totalSeconds+" seconds"); } public static void songsBySpecificArtist(SongEntry entries) { sc = new Scanner(System.in); System.out.println("OUTPUT SONGS BY SPECIFIC ARTIST"); System.out.println("Enter artist's name: "); String artistname = sc.nextLine(); while(entries != null) { if(entries.getArtistName().equals(artistname)) { entries.printPlaylistSongs(); } entries = entries.nextNode; } } /** * @param args */ public static void main(String[] args) { System.out.println("Enter playlist's title: "); sc = new Scanner(System.in); String title = sc.nextLine(); printMenu(title); } } OUTPUT: Enter playlist's title: jem JEM PLAYLIST MENU a - Add song d - Remove song c - Change position of song
  • 13. s - Output songs by specific artist t - Output total time of playlist (in seconds) o - Output full playlist q - Quit Choose an option: a ADD SONG Enter song's Unique ID: s1 Enter song's name: All for you Enter artist's name: Minda Enter song's length(in seconds): 234 JEM PLAYLIST MENU a - Add song d - Remove song c - Change position of song s - Output songs by specific artist t - Output total time of playlist (in seconds) o - Output full playlist q - Quit Choose an option: a ADD SONG Enter song's Unique ID: s2 Enter song's name: good for you Enter artist's name: selena gomez Enter song's length(in seconds): 233 JEM PLAYLIST MENU a - Add song
  • 14. d - Remove song c - Change position of song s - Output songs by specific artist t - Output total time of playlist (in seconds) o - Output full playlist q - Quit Choose an option: d Enter the song's unique ID: s1 All for you removed JEM PLAYLIST MENU a - Add song d - Remove song c - Change position of song s - Output songs by specific artist t - Output total time of playlist (in seconds) o - Output full playlist q - Quit Choose an option: o 1. Unique ID: s2 Song Name: good for you Artist Name: selena gomez Song Length(in seconds): 233 JEM PLAYLIST MENU a - Add song d - Remove song c - Change position of song s - Output songs by specific artist t - Output total time of playlist (in seconds) o - Output full playlist q - Quit Choose an option: t
  • 15. OUTPUT TOTAL TIME OF PLAYLIST (IN SECONDS) Total Time: 233 seconds JEM PLAYLIST MENU a - Add song d - Remove song c - Change position of song s - Output songs by specific artist t - Output total time of playlist (in seconds) o - Output full playlist q - Quit Choose an option: a ADD SONG Enter song's Unique ID: s3 Enter song's name: baby Enter artist's name: justin beiber Enter song's length(in seconds): 221 JEM PLAYLIST MENU a - Add song d - Remove song c - Change position of song s - Output songs by specific artist t - Output total time of playlist (in seconds) o - Output full playlist q - Quit Choose an option: s OUTPUT SONGS BY SPECIFIC ARTIST Enter artist's name: selena gomez Unique ID: s2 Song Name: good for you
  • 16. Artist Name: selena gomez Song Length(in seconds): 233 JEM PLAYLIST MENU a - Add song d - Remove song c - Change position of song s - Output songs by specific artist t - Output total time of playlist (in seconds) o - Output full playlist q - Quit Choose an option: c CHANGE POSITION OF SONG ENTER song's current position: 1 Enter new position of song: 2 cuurent pos: 1 new pos: 2 JEM PLAYLIST MENU a - Add song d - Remove song c - Change position of song s - Output songs by specific artist t - Output total time of playlist (in seconds) o - Output full playlist q - Quit Choose an option: o 1. Unique ID: s3 Song Name: baby Artist Name: justin beiber Song Length(in seconds): 221 2. Unique ID: s2
  • 17. Song Name: good for you Artist Name: selena gomez Song Length(in seconds): 233 JEM PLAYLIST MENU a - Add song d - Remove song c - Change position of song s - Output songs by specific artist t - Output total time of playlist (in seconds) o - Output full playlist q - Quit Choose an option: q