Date | November 2020 | Marks available | 5 | Reference code | 20N.2.SL.TZ0.12 |
Level | SL | Paper | 2 | Time zone | no time zone |
Command term | Describe | Question number | 12 | Adapted from | N/A |
Question
The management of the company will launch a new scheme to give every 50th car driver and every 60th motorcyclist a free coffee voucher. The code for printing this voucher has already been created and is activated by calling the static method Vouchers.printCoffeeVoucher()
.
A getKind()
method has already been added to the Vehicle
class, which returns a char
value indicating whether it is a car (c
) or a motorbike (m
).
One test performed on the finished code was defined as follows:
Describe, without writing code, any changes required to the addVehicle
method and the ParkingArea
class to make the new voucher scheme work.
Identify three other tests you might perform on the completed code to prove that it functions correctly.
The removeVehicle
method of the ParkingArea
class searches in the array for a Vehicle
object with a specified registration plate, then removes it by setting that array index to null
.
The method returns a reference to the Vehicle
object that has been removed from the array, or null
if no matching registration plate was found.
Construct the removeVehicle
method.
Markscheme
Award [5 max].
Award [1] for declaring both the variable for total cars and the variable for total motorbikes at class level (private);
Award [1] for initializing the variables, either by calling a mutator method, while declaring, or in the constructor;
Award [1] for deciding whether the car or motorbike is 50th or 60th in the daily additions;
Award [1] for printing the message if so;
Award [1] for incrementing the appropriate counter for the total cars / motorbikes added based on the value returned by getKind()
;
Note: Do not award marks for simply adding mutator or accessor methods for the motorbike / car totals.
Award [3 max].
Car:
Award [1] for Car count mod 50 is 0, coffee voucher
;
Award [1] for Car count mod 50 is n, n coffee vouchers
;
Motorbike:
Award [1] for Motorbike count mod 60 is not 0, No coffee vouchers
;
Award [1] for Motorbike count mod 60 is n, n coffee voucher
;
Non Car/Motorbike
Award [1] for Any amount of instances of the Vehicle class which are neither Car nor Motorbike, No coffee voucher
Note: do not award a mark for first test case above which is already give in question stem
Examples:
Award [6 max].
Award [1] for correct loop;
Award [1] for checking if not null;
Award [1] for checking registration using the getRegistration().equals() method;
Award [1] for setting vehicles[i] to null;
Award [1] for returning the reference (not the null element of the array), by making another variable;
Award [1] for returning null if it is not found;
Example 1:
public Vehicle removeVehicle(String registration) {
for (int i = 0; i < vehicles.length; i++) {
if (vehicles[i] != null &&vehicles[i].getRegistration().equals(registration)) { //question - why
do it in this order?
Vehicle leaving = vehicles[i];
vehicles[i] = null;
return leaving;
}
}
return null;
}
Example 2:
public Vehicle removeVehicle(String registration)
{ Vehicle v = null;
boolean found = false;
int i = 0;
while (!found && i < Vehicles.length)
{ found = Vehicles[i] != null &&
registration.equals(Vehicles[i].getRegistration());
if (found)
{ v = Vehicles[i];
Vehicles[i] = null;
}
else i = i + 1;
}
return v;
}
Examiners report
This was a good test of logical thinking. Students need to be precise: "Include two new integer variables in the ParkingArea class to hold the total number of cars and motorcycles" is clearly better than "keep count of the different vehicles".
This was poorly answered, with many answers being too vague. Similar to the requirements in the IA-section B, the tests need to give both specific test data and the expected results.
This was similar to 11(a) and students who answered the first one successfully also tended to answer this one well. Care needs to be taken when methods return something that types match with the return type indicated in the method signature.