Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you modify case d and c in main? import java.util.Scanner; public class Playlist { //--------------------------------------------------------------------------------------------------------------// public static char printMenu(String title, Scanner scnr){ char userOption;

image text in transcribed

Can you modify case d and c in main?

import java.util.Scanner;

public class Playlist {

//--------------------------------------------------------------------------------------------------------------// public static char printMenu(String title, Scanner scnr){ char userOption; System.out.println(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(); System.out.println("Choose an option:"); userOption = scnr.nextLine().charAt(0); return userOption; }

////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static void main(String [] args) { Scanner scnr = new Scanner(System.in); String uniqueID, songName, artistName, playlistTitle; int songLength, counter = 0; char menuOption = ' '; SongEntry headNode = null, currNode = null, tailNode = null; // Prompts the user for the title of the playlist. System.out.println("Enter playlist's title: "); playlistTitle = scnr.nextLine(); headNode = new SongEntry(); // headNode currently points to null tailNode = headNode; // tailNode points to null, but will be at the end of the list while (menuOption != 'q') { menuOption = printMenu(playlistTitle, scnr); switch (menuOption) { case 'A': case 'a': System.out.println("ADD SONG"); System.out.println("Enter song's unique ID:"); uniqueID = scnr.nextLine(); System.out.println("Enter song's name:"); songName = scnr.nextLine(); System.out.println("Enter artist's name:"); artistName = scnr.nextLine(); System.out.println("Enter song's length (in seconds): "); songLength = scnr.nextInt(); scnr.nextLine(); currNode = new SongEntry(uniqueID, songName, artistName, songLength); tailNode.insertAfter(currNode); // Current List is inserted after the Previous List tailNode = currNode; // tailNode is now the New List with a nextNodePtr break; case 'D': case 'd': System.out.println("REMOVE SONG"); if (currNode != null) { // System.out.println("Enter song's unique ID:"); uniqueID = scnr.nextLine(); System.out.println("\"" + currNode.getSongName() + "\" removed. "); System.out.println("Playlist is empty "); break; case 'C': case 'c': System.out.println("CHANGE POSITION OF SONG"); System.out.println("Enter song's current position:"); int currPos = Integer.parseInt(scnr.nextLine()); System.out.println("Enter new position for song:"); int newPos = Integer.parseInt(scnr.nextLine()); System.out.println("\"" + currNode.getSongName() + "\" moved to position " + newPos + " "); break; case 'S': case 's': System.out.println("OUTPUT SONGS BY SPECIFIC ARTIST"); System.out.println("Enter artist's name:"); artistName = scnr.nextLine(); currNode = headNode; while (currNode != null) { if (currNode.getArtistName().equals(artistName)) { System.out.println(counter + "."); currNode.printPlaylistSongs(); } currNode = currNode.getNext(); counter++; } break; case 'T': case 't': int totTime = 0; System.out.println("OUTPUT TOTAL TIME OF PLAYLIST (IN SECONDS)"); currNode = headNode; while (currNode != null) { totTime += currNode.getSongLength(); currNode = currNode.getNext(); } System.out.println("Total time: " + totTime + " seconds "); break; case 'O': case 'o': System.out.println(playlistTitle + " - OUTPUT FULL PLAYLIST"); counter = 0; currNode = headNode; if (currNode.getNext() == null) { System.out.println("Playlist is empty "); } else { currNode = currNode.getNext(); // Avoids printing the Head Node which is null. while (currNode != null) { counter++; System.out.println(counter + "."); currNode.printPlaylistSongs(); currNode = currNode.getNext(); } } break; default: continue; } } scnr.close(); } }

image text in transcribedimage text in transcribed

(6) Implement the "Remove song" method. Prompt the user for the unique ID of the song to be removed. (4 pts) Ex: REMOVE SONG Enter song's unique ID: "A 3134 For You" removed (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 i (the head). If the user enters a new position greater than n, move the node to position n (the tail). 6 cases wil1 be tested: Moving the head node ( 1pt ) Moving the tail node ( 1pt ) 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: CHANGE POSITION OF SONG Enter song's current position: Enter new position for song: "Canned Heat" moved to position 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions

Question

Complexity of linear search is O ( n ) . Your answer: True False

Answered: 1 week ago