Ved - Practice Paper
Ved - Practice Paper
Ved - Practice Paper
A delivery company uses trains in its operations. It uses an object-oriented program to keep track of
its trains and the parcels that it carries.
The company has many objects in their program; here are some of them.
Object Description
Each Train is made up of RollingStock objects, each of which is either a
Train
Wagon or an Engine.
A RollingStock object can be an Engine (that can pull) or a Wagon (that needs
RollingStock
to be pulled). Each RollingStock has a unique ID number and a weight.
A variety of RollingStock. Each Engine has a maximum weight that it
Engine
can pull.
Wagon A variety of RollingStock. Each Wagon has a maximum cargo weight.
Each Parcel is tagged with a tracking number, the addresses from where it came
Parcel
(origin) and to where it is going (destination) and its weight.
The code on the following pages implements the Train class used in this program.
(Option D continued)
8814-7015
– 11 – N14/4/COMSC/SP2/ENG/TZ0/XX
(Option D continued)
(b) Outline the advantages of polymorphism, using the RollingStock class as an example. [3]
(d) Construct a method getNumberOfWagons(), part of the Train class, that returns the
number of wagons currently coupled to the train. [2]
(e) Construct the removeWagon() method that will remove one wagon from a train and
return the removed object. Include appropriate error checking. [5]
(Option D continued)
11. (a) Outline one advantage of using standard library collections. [2]
(b) Describe two ways in which programming by a team differs from programming by an
individual working alone. [4]
The following code implements the Parcel class used in the delivery company’s program.
The origin and destination addresses are stored in a Parcel object as simple strings. However,
addresses are complex and there are a lot of different pieces of information that may or may not
It has been decided to create a new Address class to handle this information.
(c) State the appropriate data type to be used in the Address class to store
(d) Identify the changes to the Parcel class that will be needed to make use of the new
Address class. [3]
(e) Outline how these two new classes can be created with minimal duplication of code. [3]
8814-7015
– 13 – N14/4/COMSC/SP2/ENG/TZ0/XX
(Option D continued)
(i) Draw the mEngines array after the code fragment has been executed. [2]
(ii) State the value of mEngineCount after the code fragment has been executed. [1]
(iii) Draw the mWagons array after both the code fragment above and the code fragment
below have been executed. [2]
Wagon F = A.removeWagon();
F = A.removeWagon();
A.addWagon(new Wagon(214));
The parcels loaded into a wagon cannot weigh more than the capacity of the wagon. A train’s
engines must have enough combined power to pull the loaded wagons. The company needs to
be able to check that these requirements are being met.
(b) Construct the getWeight() method in the Wagon class that returns the total combined
weight of the parcels currently in the wagon and the wagon itself. [4]
(c) Construct the getWeight() method in the Train class that returns the total combined
weight of all the parcels, engines and wagons in a train. [4]
(d) Explain why having a getWeight() method in both the Train and Wagon classes
does not cause a compiler error, even though the Train class does not inherit from the
RollingStock class. [2]
End of Option D
8814-7015