Programming Fundamentals
To me, making a tape is like writing a letter - there’s a lot of erasing
and rethinking and starting again, and I wanted it to be a good one
... A good compilation tape, like breaking up, is hard to do. You’ve
got to kick o with a corker, to hold the attention (I started with
’Got To Get You O My Mind’, but then realised that she might
not get any further than track one, side one if I delivered what she
wanted straight away, so I buried it in the middle of side two), and
then you’ve got to up it a notch, and you can’t have white music
and black music together, unless the white music sounds like black
music, and you can’t have two tracks by the same artist side by side,
unless you’ve done the whole thing in pairs, and ... oh there are
loads of rules.
High Fidelity, Nick Hornby
1 Introduction
In today’s digital era we are spoiled for choice when it comes to audio enter-
tainment. To play a mix of our favourite songs we need only load them into our
favourite media player and hit shu e. We need not even own the songs, being
able to stream them from an online subscription service.
Pity the poor 1980s-era teenager, lumbered with analogue technology. To
make a song-mix, (s)he was forced to painstakingly play songs one by one on a
vinyl turntable, recording each one to a magnetic tape cassette. Once recorded
the mix was essentially xed; the only way to change the mix was to rewind the
tape to the desired point and re-record it. Tapes had two sides; once one side
had been lled, the tape would be manually ipped over in the recorder and
then the other side recorded. Timing songs to perfectly ll a side of the tape
was notoriously di cult, thanks in part to variability of the actual length of the
tape, and wasted seconds in between songs. Consequently each side of the tape
was often terminated by a half-song, abruptly terminated when the tape ran
out.
This assignment is a tribute to those halcyon days of analogue technology.
We will be composing a class to assist in the planning of a MixTape playlist.
2 The Task
The supplied le MixTape.java speci es the class de nition for a MixTape
object, comprising numerous methods which can be used to manipulate Songs
on a two-sided playlist. The methods are all supplied as function headers with
empty bodies, e.g. private void compactSide(char s) You must ll in each
method so it performs the actions speci ed in its header comments.
The instance variables sideA, sideB, and tapeLengthMinutes are all de-
ned. Use them in your code. Constructor methods which set up the instance
variables are supplied for you. sideA is an array of Songs, representing the rst
side of the MixTape. sideB is an array of Songs, representing the second side.
tapeLengthMinutes is the total duration of the MixTape in minutes. Each
individual side has a maximum duration equal to half of this value.
A song can be referred to by its side and track number, or by its overall
position on the tape. For example the third song on side A could be \side A
track 3" or just \track 3". If there were 7 songs on side A, then the rst song on
side B could be \side B track 1" or \track 8" overall. CAUTION: Remember
that the rst element of an array has index 0.
Each song is an instance of the Song class. This class is supplied (Song.java)
and should not be edited by you. Inspect this class and understand what it does.
A Song has instance variables title, artist, minutes and seconds. These
can be obtained via accessor methods de ned in Song. There are no mutator
methods. Song is thus an immutable class; an instance cannot be changed once
created.
MixTape has private methods getSide(), setSides() and initialiseSides()
which are all supplied for you. Understand what they do and use them in your
own methods. Output methods dump() and toString() are also supplied for
you.
Try not to re-invent the wheel. Some methods can be written more simply by
calling other methods, rather than duplicating their source code. ADVICE:
Work through the le from the top to the bottom, as the simpler functions with
no obvious dependencies on other methods appear higher in the le.
You can test your code with the supplied JUnit test le TestMixTape.java.
This can be run in eclipse like a normal Java program. The Junit tab in eclipse
(which usually appears on top of the package explorer) reports the success or
failure of each module in TestMixTape. Click on the ones which have failed in
order to get information about how they have failed (e.g. what the error is and
on what line it occurs). ADVICE: Try to get the tests working on order from
top to bottom in the TestMixTape le. This is because many of the later tests
have dependencies upon code which has already been tested by earlier tests.
Be aware that there is no JUnit test module supplied for compactSides().
Also be aware that no JUnit test modules have been supplied for the advanced
sortSides() or balanceSides() methods. Please think of your own algo-
rithms for these routines, and don’t rely upon Java API routines, i.e. no
Arrays.sort().
2.1 Getting Started
Import the supplied ZIP le into eclipse as a Java project.
2.2 Marks Allocation
All tests pass 50
Be aware that the markers may use a di erent JUnit test le from the one
which has been supplied.
sortSides() and balanceSides() implemented 10
style. 20
Consistent indentation, good choice of identi er names, proper use of com-
ments, etc.
general coding 20
Concise, well-speci ed algorithm. No wasteful code or unnecessary dupli-
cation of code.