Answer:
Answers can be found below
Explanation:
port java.util.Scanner;
public class Playlist {
String title;
SongEntry head;
public Playlist(String title) {
this.title = title;
this.head = null;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the playlist's title:");
String title = scanner.nextLine();
Playlist playList = new Playlist(title);
String option;
do {
option = playList.printMenu(scanner);
switch (option) {
case "a":
playList.addSong(scanner);
break;
case "d":
playList.removeSong(scanner);
break;
case "c":
playList.changePosition(scanner);
break;
case "s":
playList.outputSongByArtist(scanner);
break;
case "t":
playList.outpuTotalTime();
break;
case "o":
playList.outputFullPlayList();
break;
case "q":
System.out.println("QUIT");
break;
default:
System.out.println("please enter a valid option");
}
} while (!option.equals("q"));
}
public String printMenu(Scanner scanner) {
System.out.println(this.title + " PLAYLIST MENU");
System.out.println("a - Add song");
System.out.println("d - Remove song");
System.out.println("c - Change position of song");
System.out.println("s - Output songs by specific artist");
System.out.println("t - Output total time of playlist (in seconds)");
System.out.println("o - Output full playlist");
System.out.println("q - Quit");
System.out.println("Choose an option:");
String input = scanner.nextLine();
return input;
}
public void outputFullPlayList() {
if (head == null) {
System.out.println("Playlist is empty");
} else {
SongEntry tempNode = head;
while (tempNode != null) {
tempNode.printPlaylistSongs();
tempNode = tempNode.getNextNode();
}
}
}
public void addSong(Scanner scanner) {
System.out.println("ADD SONG");
System.out.println("Enter song's unique ID:");
String uniqueId = scanner.nextLine();
System.out.println("Enter song's name:");
String songName = scanner.nextLine();
System.out.println("Enter artist's name:");
String artistName = scanner.nextLine();
System.out.println("Enter song's length (in seconds):");
int length = Integer.parseInt(scanner.nextLine());
SongEntry song = new SongEntry(uniqueId, songName, artistName, length);
if (head == null) {
head = song;
} else {
SongEntry tempNode = head;
while (tempNode.getNextNode() != null) {
tempNode = tempNode.getNextNode();
}
tempNode.insertAfter(song);
}
}
public void removeSong(Scanner scanner) {
System.out.println("REMOVE SONG");
System.out.println("Enter song's unique ID:");
String uniqueId = scanner.nextLine();
SongEntry tempNode1 = head;
SongEntry tempNode2 = head;
while (tempNode1 != null) {
if (tempNode1.getUniqueID().equals(uniqueId)) {
if (tempNode1.getUniqueID().equals(head.getUniqueID())) {