THINK FIRST·CODE LATER

← All labs

Playlist manager

Problem

Write a class Song (title, seconds, toString → Intro (1:05)) and a public class Playlist that keeps an ArrayList<Song>. Commands until the end of input:

  • add TITLE SECONDS — at the end; first TITLE SECONDS — at the front (add(0, …));
  • remove TITLE — prints no song TITLE if it is absent;
  • up TITLE — swaps the song with the one before it (use get and set);
  • show — numbered list, then 3 songs, 9 min 40 s, longest: Finale.

Write a helper int find(ArrayList<Song> songs, String title).

For the input

add Intro 65 add Anthem 240 add Finale 275 show up Finale first Hello 30 remove Anthem remove Missing show

the program prints

1. Intro (1:05)
2. Anthem (4:00)
3. Finale (4:35)
3 songs, 9 min 40 s, longest: Finale
no song Missing
1. Hello (0:30)
2. Intro (1:05)
3. Finale (4:35)
3 songs, 6 min 10 s, longest: Finale

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

l13-6-data-1.txt

add Intro 65 add Anthem 240 add Finale 275 show up Finale first Hello 30 remove Anthem remove Missing show
What your program must print for l13-6-data-1.txt
1. Intro (1:05)
2. Anthem (4:00)
3. Finale (4:35)
3 songs, 9 min 40 s, longest: Finale
no song Missing
1. Hello (0:30)
2. Intro (1:05)
3. Finale (4:35)
3 songs, 6 min 10 s, longest: Finale

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < l13-6-data-1.txt

Windows PowerShell does not understand <:

Get-Content l13-6-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.