home—info—archive—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
hw09
songs
due Apr.02
Write a program to represent a Song in a music collection.
You must be to represent the types of information shown in the following
screenshot:
In addition, you will need to represent a filename
(a String) for each song.
After declaring your fields,
use Eclipse to automatically generate
the constructor, getters, and (where appropriate) setters.
(Be sure to have eclipse generate comments you create these
methods, and then go back and complete those comments.)
Be sure to name your class Song.
Your code must be able to answer the following questions about songs:
-
What is the length of the song, in seconds?
-
What is a string representing the length of the song
(in minutes and seconds).
-
Is the song on a given album?
(That is, you walk up to a song and give it an album,
and ask whether it is on that album.)
-
Is one song a cover version of another?
(It's up to you to decide how to try to automatically detect this;
make sure you make test cases where two songs are considered
cover versions of each other,
and two other songs which aren't.
-
Is one song ranked higher than another?
-
added Mar.29 (Sat) noon
Play a song.
That is, update its information in response to
be played right then (the day your method is called,
not the day you write the method).
(You can use our Date class from lab;
no modification is necessary, so you don't need to turn in any
tests/docs/code for that class.)
Clarifications
-
This problem specifically requires you to think about
what fields are needed, and what method signatures should be like.
(Similar to some of our lectures where we brainstormed fields and methods.)
-
This problem does not need to be approached
the same way that the exam2-practice-exam was.
(You don't need to have two classes to separate
the information of song-files from the information of song-plays.)
-
Use the Date class.
It should only need the following minor modifications:
-
We now realize that today a static method,
and
-
change the name of boolean sameDateAs( Date other )
to public boolean equals( Date other ).
You don't need to turn in any documention or tests for Date
if you don't make changes beyond the two mentioned here.
-
The last-played doesn't need to keep track of time-of-day,
if you don't want.
(You are welcome to add that if you want, though.)
-
Yes you need to write test cases and documentation.
You can turn those in Monday if you like,
but they'll be accepted Wednesday as well.
Note:
you will re-use this same class
in a future homework, where will create lists of your song objects.
On that homework, we'll write functions which do things like:
-
find the most popular song in a playlist
(ties broken by most-recently-played),
-
find the longest song which has never been played,
-
Choose a random song from a playlist (each song equally likely),
-
Choose a random song from a playlist (longer songs more likely than
shorter songs, proportionally)
etc.
home—info—archive—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs