A music app keeps playlists: songs in the order they were added. Build it from two classes that work together. A Song holds one song's data. A Playlist keeps a list of Song objects and answers questions about them.
Implement:
Song(title, seconds)holds a song'stitleand its length inseconds;Playlist()starts with no songs. Its methods:add(song)adds aSongat the end of the playlist;remove(title)removes the first song with that title and returnstrue; if no song has that title, it changes nothing and returnsfalse;totalSeconds()returns the sum of the songs' lengths in seconds (0 for an empty playlist);duration()returns the same total as a string"m:ss": the minutes, a colon, then the seconds with two digits. 5 seconds are"0:05", 750 seconds are"12:30", and 3600 seconds are"60:00": the minutes are never padded.
The starter code spells every name the way your language does.
The input is a list of operations, applied in order to one new playlist. The output lists what the remove, totalSeconds and duration calls return, in order, with booleans printed as True and False.
Example 1:
Input:
add(Song("Intro", 65))
add(Song("Sunrise", 200))
totalSeconds()
duration()
remove("Intro")
duration()
Output: 265 4:25 True 3:20
Explanation: The two songs last 65 + 200 = 265 seconds: 4 minutes (240 seconds) and 25 seconds.
After "Intro" is removed, only the 200 seconds of "Sunrise" are left: 3 minutes and 20 seconds.
Example 2:
Input:
duration()
remove("Rain")
totalSeconds()
Output: 0:00 False 0
Explanation: The playlist is empty: it lasts 0 seconds, and there is no "Rain" to remove.
Example 3:
Input:
add(Song("Echo", 30))
add(Song("Echo", 45))
add(Song("Rain", 5))
remove("Echo")
totalSeconds()
remove("Echo")
remove("Echo")
duration()
Output: True 50 True False 0:05
Explanation: Two songs are called "Echo". The first remove takes only the first one, the 30 seconds,
so 45 + 5 = 50 seconds are left. The second remove takes the other "Echo", and the third finds none.
Only "Rain" is left: 5 seconds, written 0:05.
Constraints:
1 <= seconds <= 3600- A title is one word of letters and digits. Titles are compared exactly: "Rain" and "rain" are different titles.
- At most 200 operations.
Free plan: 30 tutor messages. PRO is unlimited.
