← Unit 3 · all exercises
Saved in this browser only

A playlist

Write a Playlist tracking a song count and a total length in seconds, both starting at zero. addSong takes a length and updates both. totalMinutes returns the total length in whole minutes, rounded down.

class Playlist { Playlist(); void addSong(int seconds); int songCount(); int totalMinutes(); }

Playlist.java
Loading editor…
Results

Examples

  • Playlist p = new Playlist(); p.addSong(120); p.addSong(180); p.totalMinutes() → 5
  • Playlist p = new Playlist(); p.addSong(120); p.songCount() → 1

There are also 3 hidden tests you can't see. Solve the problem, not the examples.