CSE 131 Module 5: Modular Design
Name (print) ___________________________________ Lab Section you attend______________
CSE131 Quiz 5
3 Oct 2008
The optional extension can be found here.
Suppose you are given three classes: Song,
Artist, and MP3Player. Songs have a length
and are sometimes CountryWestern. Every Artist has a top hit Song and
a count of the number of Songs recorded by the Artist.
A Song can be added to an MP3Player, and a (random) Song can be
removed from an MP3Player only if the MP3Player is not empty.
An MP3Player can tell you the last Song it played.
| Song || Artist || MP3Player |
- int getLength()
- boolean isCountryWestern()
- Song getTopHit()
- int getNumSongs()
- boolean isEmpty()
- Song removeOneSong()
- void addSong(Song s)
- Song lastPlayed()
- (50 pts) Based on the above methods, provide the type (and make up a suitable
name) for one instance variable of any one of the above classes.
(Yes, I only need one such thing here, not one for each class. Tell
me which class would have the instance variable.)
Using the above methods, write a Java code fragment (below or on the
back of this page) to perform
each of the following tasks (Choose any two, 25 points each):
Choose any two of the following:
- Given two Artists, a1 and a2,
determine how long it would
take to play both of their top hit Songs.
- Given an Artist a, determine if a is
a one-hit wonder (ask me if this is unclear).
- Determine if an MP3Player m has never played
- Given two MP3Players mine and yours,
remove every Song from yours and add it to mine.
- Given an MP3Player m, keep removing Songs
from m until m is
empty or a Country Western Song has been removed.