RHS   Allan   BasicProgramming => Exercises => ToursiticRental2


 
Touristic Rental 2

As the module concerning bicycle rental is to be incorporated into the overall system for "Touristic Rental" some adaption is needed - we'll only scratch the surface here.

Remember that other types of equipment than bicycles are to be offered for rent (cars, clothes, baby-equipment etc.)
It turns out that many methods used to manage these equipments need a way to identify the individual pieces.

Bicycle has the attribute serialNo for identification, but other types of equipment uses same numbers - thus it is necessary to extend the way we identify equipment.

It is decided to use two attributes for a unique identification: a serial-number (integer) and a type-description (string).
It is crucial that all equipment is identifiable using these two attributes.
To enforce this it is decided that all equipment-classes should be of a type named identifiable.

It must be ensured that any object of the type identifiable contains two methods: getSerialNo() and getTypeDescription() - the first must return an integer value, the second must return a String. If all objects have these methods it will be possible to use the combination of these two methods for object-identification.

Question 2 Interface
Implement an interface named Identifiable that declares the two methods.

Adapt your class Bicycle so it implements the interface.
You should remember to add the type-description variable and include it in constructors.
Also consider if you need to change existing methods and if you have to add new methods.

 

It turns out that all bicycles owned by "Touristic Rental" are either of the type "Sports Bike" or of the type "City Bikes" - no objects of the class Bicycle are needed.
Further it is believed that this will hold true in the future as all bicycles will be of a special kind in some way.

Also it should be necessary to compute the rent the tourist must pay. The rent depends on both the number of hours the bicycle has been rented and the basic-rate for the individual bicycle.
The rent is calculated differently for the two types and it is believed that each type of bicycle in the future will have its own way of calculating the rent.

For “City Bikes” the rent is calculated in the following way (hours will be passed as argument to the method that calculates the rent):

 0 < hours <=  6 :  rent = 45 + basicRate * hours
 6 < hours <= 12 :  rent = 35 + basicRate * hours
12 < hours       :  rent = 15 + basicRate * hours

For “Sports Bikes” the rent is always calculated as:

     Always :  rent = 75 + basicRate * hours

Question 3 Abstract class
Change the class Bicycle so it describes an abstratc class. Add the declaration of an abstract method: public double getAmount().
Change the implementation of the sub-classes as needed (use the formulas above for calculating the rent).


Question 4 Discussion
The final design has two sub-classes (SportsBike and CityBike) extending an abstract class (Bicycle) that implements an interface (Identifiable).

In groups of 3 or 4 people you should discuss the following:


Maintained by: Allan Helboe Nielsen
Updated: 3 November, 2005 1:04