Date | May 2019 | Marks available | 2 | Reference code | 19M.2.SL.TZ0.10 |
Level | SL | Paper | 2 | Time zone | no time zone |
Command term | Outline | Question number | 10 | Adapted from | N/A |
Question
An international school organizes a regional swimming competition for students from 10 different schools. Each school will send a team of 5 to 15 swimmers.
Each swimmer can enter up to 5 events (such as the “50 m freestyle” or “100 m butterfly”).
Each event consists of one or more races. A race can be a qualifying heat, or a final. The final has the best 8 swimmers from all the qualifying heats in the event.
Each race has a maximum of 8 swimmers.
The UML diagrams for the classes Swimmer
and Race
are provided below.
In this scenario, Swimmer
objects are aggregated in a Race
object.
Define the term mutator method.
State one additional instance variable of type boolean
which could be added to the class Race
as indicated above.
With reference to both class UMLs provided above, distinguish between a class and an instantiation.
Outline one advantage of using aggregation in this context.
Outline one disadvantage of using aggregation in this context.
Construct code for the constructor of the class Swimmer
that instantiates an object with parameters name
and school
. The event IDs should be set to “empty” and the times to 0.0
Many swimmers in the event have names that cannot be represented using basic character sets such as ASCII.
Describe one feature of modern programming languages that allows the wide range of students’ names to be represented correctly.
Markscheme
Award [1 max].
A method that allows/controls changes to a private (hidden) variable;
Award [1 max].boolean isFinals
;
Award [3 max].
The class Swimmer
is the blueprint of a Swimmer
object;
An instantiation is the actual object filled with data;
The class Race
stores up to 8 different instantiated objects of the Swimmer
class;
Award [2 max].
Award [1] for identifying an advantage and [1] for an elaboration of the advantage up to [2 max].
Aggregation reduces dependencies;
and therefore reduces maintenance overhead;
Award [2 max].
Award [1] for identifying a disadvantage and [1] for an elaboration of the disadvantage up to [2 max].
Aggregation of swimmers in a object can cause issues with processing;
e.g. when searching for all heats that a particular swimmer participates in;
Award [4 max].
Award [1] for correct signature including parameters.
Award [1] for assigning name and school.
Award [1] for a (any) loop.
Award [1] for assigning empty to eventID[i]
.
Award [1] for assigning 0
(or 0.0
) to time[i]
.
Example answer:
public Swimmer(String name, String school)
{
this.name = name;
this.school = school;
for(int i = 0, i < 5; i++)
{
eventID[i] = "empty";
time[i] = 0;
}
}
Award [3 max].
Modern programming languages use Unicode to encode characters.
Which uses 16 bits / has about 64 000 characters.
As opposed to ASCII which uses 8 bits / has 256 characters.
Examiners report
This was answered well. As this is an OOP course, some reference to objects, classes or encapsulation was expected which most students gave.
Any sensible and non-trivial answer was accepted.
Some candidates experienced difficulties in clearly distinguishing between the two terms. For the purpose of this course, a class is the template for objects which are created by instantiation.
Candidates struggled to give a clear advantage (e.g. better organization) for aggregation.
Candidates struggled to give a clear disadvantage (e.g. dependencies) for aggregation.
This was well-answered.
It was clear from the various guesses that this topic hadn't been covered in some schools.