December 1999
JP219 : JAVA PROGRAMMING

QUESTION 5

Total Marks: 15 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 5

 

A vehicular transportation device is a facility used by people to travel around Singapore. These devices have specific properties,namely the number of people they can carry,called People ,and a maximum speed,called Speed .Consider the following definition of a vehicular transportation device class,called VTD :

public class VTD {
  protected int People;
protected int Speed;
VTD(int p,int s){

 

}

People=p;
Speed=s;
}  

 

 
(a)

Define a class,called Car ,which inherits the properties of the VTD class,and also has the additional property of a Manufacturer ,which is a String .Your class should contain a constructor method which takes all the member attributes as parameters, correctly initialises all attributes and instantiates the base class with the appropriate parameters.

 

[5]
(b)

A Skip is a large metal container,used for the storage of large obsolete industrial components.Define an interface ,called Skip which contains a method declaration called AddJunk ,which takes no parameters.

 

[2]

(c)

A Ute is a very special type of vehicular transportation device,in that it can perform the function of a Car ,and can also be used as a Skip ,for the storage and disposal of junk. Implement a class,called Ute ,which inherits the properties of your Car class and your interface Skip .In addition to this,your class should include the following:

•The protected member NumberJunkItems ,of type int ;

•A constructor method,which takes all the member attributes as parameters,and instantiates and initialises them as appropriate.

•The implementation of the interface method AddJunk ,which simply increments the value of JunkCapacity .The implementation should ensure that no subsequent derived classes can overload this implementation.

[8]