RHS   Allan   BasicProgramming => Exercises => TouristicRental


 
Touristic Rental

The Company “Touristic Rental” rents various objects to tourists, e.g. bicycles, cars, equipment for children etc. To manage their business the company wants an application for registration of their objects, rental agreements and financial transactions.

In this assignment you are only to deal with the bicycle rental!

Note: The purpose of this exercise is to get some experience with inheritance, abstract classes and interfaces. Normally the implementation would be done on the basis of a analysis and design - providing diagrams and documentation for the programmer. As we will evolve from the simple (extending classes) to the more complex (abstract class and interface) we'll do it the other way around as if the final design is not known. In a way we'll proceed in the same way as you would do if you were using extreme programming - analyzing and designing will be done as the code is developed.


Two different kinds of bicycles are offered for rent by “Touristic Rental”: “City Bikes” and “Sports Bikes”.
The main difference is that “City Bikes” always has only one gear whereas “Sports Bikes” has individual number of gears.
Also a CityBike can be equipped with a baby-seat (but not all CityBikes holds a baby-seat).

The following description of the three classes reflects the structure needed:

Bicycle
All bicycles hold a serial-number (a integer value) for identification and a basic-rate (a double value) used in calculating the rent.

Three constructors are needed: One with no parameters, one that only takes the serial-number and finally one that takes the serial-number and the basic-rate as parameters.

To read values from an object we need get-methods for the serial-number and basic-rate.

Only the basicRate should be changed so we only need set-method for the basic-rate.

CityBike
A boolean value should be used to store the information whether a baby-seat is installed.

It should be possible to read and change this value.

Also an extra constructor is needed that takes values for all variables. Constructors should reuse the constructors from the super-class as much as possible (consider the advantages)

SportsBike
An integer value should hold the number of gears - it should be possible to read but NOT change this value. To initialize the value all constructors should take a parameter for the number of gears - except of course the no-args constructor (the constructor with no parameters). Again the super-class constructors should be reused as much as possible.

A business rule at “Touristic Rental” demands that the basic-rate for a SportsBike must be at least 5 - thus you should adapt the constructors and the set-method for the basic-rate value so any parameter value less than 5 will be ignored and the value will be set to 5.

The following UML-diagram reflects this description:

   


Question 1 Class hierarchy
Implement the 3 classes, Bicycle.java, CityBike.java and SportsBike.java as described.

Also implement an application-class, TouristicRental.java, that creates at least one object of each class and tests their methods. Also experiment with assigning objects of one type to references of another type. Note which combinations are possible and which methods are available for the possible ones.

Finally assign a CityBike object to a reference of the Bicycle type and use this reference in another statement where you assign the object to a reference of the CityBike type.

To be continued.....


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