We want to realize a program to be used by a DVD rental shop to manage DVDs to be rented. For each DVD, the following information is stored:
Part 1.
Write a class DVD
that implements the following methods:
DVD(String title, int age)
: costructor that, given title
and age, constructs a DVD that is initially not rented;
String getTitle()
: that returns the title of the DVD;
int getAge()
: that returns the age for which the DVD is
suited;
int getDays()
: that returns the number of days that the
video is rented;
String getName()
: that returns the name of the person that
rented the DVD, if the DVD is rented, and null
otherwise;
void rentDVD(String n, int d)
: that rents the DVD to the
person with name n
for d
days, if it is not
already rented, and otherwise does nothing;
void giveBackDVD()
: that sets the status of the DVD to
being not rented (this means also that there is no person who rents the
DVD);
String toString()
: that returns a string with all the
information about the DVD.
Example program:
TestDVD.Java
Part 2.
Write a classUseDVD
, client of DVD
, that contains
the following public static method:
static String shortestRental(DVD d1, DVD d2)
: that, given two
DVDs d1
and d2
, returns the name of the person
who rented for the shortest period the DVDs among d1
and
d2
. If both d1
and d2
are rented
for the same number of days, the method should return the name of the
person who rented d1
. If only one of d1
or
d2
is rented, the method should return the name of the
person who rented that DVD. If both d1
and d2
are not rented, the method should return null
.
Example program:
TestUseDVD.java
Solutions:
DVD.java
,
UseDVD.java