Implement a class Tape
. An instance of Tape
represents a video tape that can hold recorded television programs. For each
program recorded on a tape, the following properties are of interest:
Each tape has a certain capacity (in minutes) and each recorded program starts
at a certain position on the tape. The positions are numbered as 0, 1, 2, 3,
... The class Tape
should implement the following features:
getResidualCapacity():
getNumberOfPrograms()
:
record()
:
record()
appends the program to the tape - if there's
not enough space left to contain the program
a RuntimeException
should be thrown;
getProgram()
:
getProgram()
returns the program recorded at that position - if there is no program
recorded at that position a RuntimeException
should be thrown;
getLength()
:
getLength()
returns the length in minutes of the program recorded at that position - if
there is no program recorded at that position
a RuntimeException
should be thrown;
Part 1
Implement a class Tape
using a linked list to store informations
about the programs on the tape.
Solution:
representation of the objects,
skeleton of the class,
class Tape
Part 2
Implement a client class for Tape
. It should have a static method
that, given a Tape
instance and a file name as parameters, writes
the program listing (name and length of each recorded program) to the file. The
static method should also write the total length of all recorded programs and
the residual capacity of the tape to the same file.
Part 3
Implement a test program that creates a Tape
, records a few
programs on it and then calls the static method from part 2 to write the tape's
information to a file.