Further programming: paradigms, OOP, files and exceptions – A Level Computer Science (9618)

24 questions · page 1 of 2 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
1
9618/41/M/J/26 · Question 3May/June 2026Paper 4121 marks
Loading question…
Question text

3
A prototype for a game is designed using Object‑Oriented Programming (OOP).
The game will allow a character to move along a path (for example a road or sidewalk).
The prototype requires the classes setting up and the path creating ready for the character to
be implemented.
(a) Each space in the path can contain an object. The path and objects are created as classes.
The class TheObject stores the data about the objects. The attributes are public.
TheObject
ObjectType : String
stores the type of object, either "Money" or "Experience"
Amount : Integer
stores the amount of the object, for example 200
Constructor()
initialises the attributes to the parameter values
The class Path stores the data about the objects. The attributes are public.
Path
BoardArray[0:99] : TheObject
an array of 100 objects of type TheObject
NumberSpaces : Integer
stores the number of spaces in the path
Constructor()
initialises NumberSpaces to the parameter value.
Initialises all 100 array objects to an empty object of type
TheObject. An empty object has the values
ObjectType = "" and Amount = –1
GetNumberSpaces()
returns NumberSpaces
InitialiseData()
takes an array of objects of type TheObject as a
parameter and stores them in BoardArray
ReturnPath()
returns a string created using data from each object
in BoardArray
GetPathObject()
takes a number as a parameter and returns the object in
that index in BoardArray
Write program code to declare the class TheObject and its constructor.
(i)
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question3_J26.
Copy and paste the program code into 3(a)(i) in the evidence document.
[4]
© Cambridge University Press & Assessment 2026
Write program code to declare the class Path, its constructor and
(ii)
method GetNumberSpaces()
Use your programming language appropriate constructor.
Do not declare the other methods.
If you are writing in Python, include attribute declarations using comments.
Save your program.
Copy and paste the program code into 3(a)(ii) in the evidence document.
[4]
The method InitialiseData() takes an array of type TheObject as a parameter.
(iii)
The method stores each element from the parameter array into the array BoardArray
in the same order.
If there are more objects in the parameter array than in NumberSpaces, the method
does not store the data and returns FALSE. Otherwise, it returns TRUE
Write program code for InitialiseData()
Save your program.
Copy and paste the program code into 3(a)(iii) in the evidence document.
[3]
The method ReturnPath() creates and returns a string containing the type and
(iv)
amount of each object that is not a null object in BoardArray, in the format:
<ObjectType>-<Amount>
For example, an array with two not null objects produces the string:
Money-100 Experience-50
You can assume that there will always be an object that is not null in BoardArray
Write program code for ReturnPath()
Save your program.
Copy and paste the program code into 3(a)(iv) in the evidence document.
[2]
© Cambridge University Press & Assessment 2026
The method GetPathObject() takes an integer index as a parameter and returns the
(v)
object at the parameter index in BoardArray
Write program code for GetPathObject()
Save your program.
Copy and paste the program code into 3(a)(v) in the evidence document.
[1]
(b) (i)
Write program code for the main program to:
•
create a new array, ArrayOfObjects, of type TheObject with five spaces
•
store the following objects in each space in ArrayOfObjects in the order given:
money with amount 50
experience with amount 100
money with amount 200
money with amount 20
experience with amount 30
•
create a new object, Path1, of type Path with five spaces
•
call InitialiseData() for Path1 with ArrayOfObjects
•
call ReturnPath() for Path1 and output the return value.
Save your program.
Copy and paste the program code into 3(b)(i)

2
9618/42/M/J/26 · Question 2May/June 2026Paper 4230 marks
Loading question…
Question text

2
A program stores data about avatars in a program using Object‑Oriented Programming (OOP).
An avatar is a character that a user can control in a game.
The class Avatar stores the data about avatars.
Avatar
TheName : String
stores the name of the avatar
Glasses : Boolean
stores TRUE if the avatar wears glasses
stores FALSE if the avatar does not wear glasses
Hair : String
stores the colour of the avatar's hair
Age : Integer
stores the age of the avatar
Constructor()
initialises all attributes to its parameter values
GetName()
returns the name of the avatar
GetAge()
returns the age of the avatar
MeetCriteria()
takes the glasses choice and hair choice as parameters
and returns whether the avatar matches the choices
Write program code to declare the class Avatar and its constructor. All attributes must
(a) (i)
be private.
Do not declare the other methods.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question2_J26.
Copy and paste the program code into 2(a)(i) in the evidence document.
[4]
The get methods GetName() and GetAge() each return the relevant attribute.
(ii)
Write program code for GetName() and GetAge()
Save your program.
Copy and paste the program code into 2(a)(ii) in the evidence document.
[3]
© Cambridge University Press & Assessment 2026
The method MeetCritera() takes two parameters:
(iii)
•
a Boolean value to identify whether the avatar wears glasses
•
a string value to identify the hair colour.
The method checks whether this avatar’s attributes match both of the parameters.
Boolean TRUE is returned when both of the attributes match the parameters, otherwise
Boolean FALSE is returned.
Write program code for MeetCriteria()
Save your program.
Copy and paste the program code into 2(a)(iii) in the evidence document.
[2]
The text file AvatarFile.txt stores data for 30 avatars. Each avatar is on a new line
(b) (i)
in the file. The data is stored in the order: name, glasses, hair colour, age. Each value is
separated by a space.
For example, the first line in the file is:
Kit True blonde 21
The name of the avatar is Kit, the avatar wears glasses, the avatar has blonde hair, the
avatar is 21 years old.
The procedure LoadAvatars() reads the data from the text file into the program. The
function creates a new object for each avatar in the file and stores the avatar objects in
a global array with the identifier AvailableAvatars
The procedure uses exception handling when opening and reading from the file.
Write program code for LoadAvatars()
Save your program.
Copy and paste the program code into 2(b)(i) in the evidence document.
[7]
Write program code for the main program to call LoadAvatars()
(ii)
Save your program.
Copy and paste the program code into 2(b)(ii) in the evidence document.
[1]
© Cambridge University Press & Assessment 2026
The procedure EnterChoices() prompts the user to enter whether they want an
(c) (i)
avatar that wears glasses and the hair colour they want.
The procedure takes these two values as input until they are valid:
•
wearing glasses can only be yes or no
•
the hair colour can be black, blonde, brown, pink, red or green.
The procedure calls the method MeetCriteria() for each avatar in
AvailableAvatars and stores the avatars that match the criteria in a global array.
Write program code for EnterChoices()
Save your program.
Copy and paste the program code into 2(c)(i) in the evidence document.
[6]
(ii)
Write program code to extend the main program to:
•
call EnterChoices()
•
output the quantity of avatars that match the criteria
•
output the name and age of each avatar that matches the criteria.
All outputs must include an appropriate message.
Save your program.
Copy and paste the program code into 2(c)(ii) in the evidence document.
[5]
© Cambridge University Press & Assessment 2026
(d) (i)
Test your program with the following data as input:

3
9618/43/M/J/26 · Question 2May/June 2026Paper 4329 marks
Loading question…
Question text

2
A prototype for a game is being developed using Object‑Oriented Programming (OOP).
The game has a set of characters that have data stored about their characteristics, for example
if the character can fly or not fly. A user has to select their requirements, for example a character
that can fly, and the program will output the characters that meet the user’s requirements.
The class Character stores the data about the characters. The attributes are public.
Character
CharacterName : String
stores the character’s name
Colour : String
stores the colour of the character, for
example "Green"
SuperStrength : String
stores whether the character has super strength
("Yes") or not ("No")
Fly : String
stores whether the character can fly ("Yes") or
not ("No")
Invisible : String
stores whether the character can become
invisible ("Yes") or not ("No")
Constructor()
initialises the attributes to its parameter values
GetCharacterName()
returns CharacterName
GetColour()
returns Colour
GetSuperStrength()
returns SuperStrength
GetFly()
returns Fly
GetInvisible()
returns Invisible
Write program code to declare the class Character and its constructor.
(a) (i)
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question2_J26.
Copy and paste the program code into 2(a)(i) in the evidence document.
[4]
© Cambridge University Press & Assessment 2026
The get methods GetCharacterName(), GetColour(), GetSuperStrength(),
(ii)
GetFly() and GetInvisible() each return the appropriate attribute.
Write program code for GetCharacterName(), GetColour(),
GetSuperStrength(), GetFly() and GetInvisible()
Save your program.
Copy and paste the program code into 2(a)(ii) in the evidence document.
[3]
(b) The text file Characters.txt stores data about 15 characters. Each character is on a new
line in the file. The data is stored in the order: Character name, colour, super strength, fly,
invisible. Each value is separated by a comma.
For example, the first line in the file is:
Jet,Black,Yes,No,No
The name of the character is Jet. The colour of the character is Black. The character has
super strength. The character cannot fly. The character cannot become invisible.
The function ReadData():
•
opens the file Characters.txt and reads in the data
•
creates a new Character object for each character in the file
•
stores each Character object in a local array
•
returns the populated array.
The function uses exception handling when opening and reading from the file.
Write program code for ReadData()
Save your program.
Copy and paste the program code into 2(b) in the evidence document.
[7]
© Cambridge University Press & Assessment 2026
(c) The procedure OutputCharacters() takes an array of Character objects as a
parameter. The procedure outputs the data for each character on a new line, in the format:
Name: <Character name> Colour: <Colour> Super strength: <Super
strength> Fly: <Fly> Invisible: <Invisible>
For example:
Name: Jet Colour: Black Super strength: Yes Fly: No Invisible: No
Write program code for OutputCharacters()
Save your program.
Copy and paste the program code into 2(c) in the evidence document.
[3]
The main program calls ReadData() and then OutputCharacters() with the
(d) (i)
returned array.
Write program code for the main program.
Save your program.
Copy and paste the program code into 2(d)(i) in the evidence document.
[2]
(ii)
Test your program
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into 2(d)(ii) in the evidence document.
[1]
© Cambridge University Press & Assessment 2026
(e) The main program needs to give the user two choices to limit the characters that they can
choose from. For example, they could choose to only see characters that are green and that
can fly.
(i)
The main program needs extending to:
•
prompt the user to enter two criteria and take both as input.

Advertisement
4
9618/41/O/N/25 · Question 2Oct/Nov 2025Paper 4130 marks
Loading question…
Question text

2
A program stores data about trains and train stations using Object-Oriented Programming (OOP).
The class Train stores the data about the trains:
Train
TrainIDNumber : String
stores the train ID number
Route : Integer
stores the route number the train is travelling
initialises TrainIDNumber and Route to the parameter
Constructor()
values
GetTrainIDNumber()
returns the train ID number
GetRoute()
returns the route number the train is travelling
Write program code to declare the class Train and its constructor.
(a) (i)
Do not declare the other methods.
All attributes should be private.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question2_N25.
Copy and paste the program code into part 2(a)(i) in the evidence document.
[4]
The methods GetTrainIDNumber() and GetRoute() return the appropriate attribute.
(ii)
Write program code for GetTrainIDNumber() and GetRoute()
Save your program.
Copy and paste the program code into part 2(a)(ii) in the evidence document.
[3]
(b) The program is tested with four trains:
train ID number
route
12ADV
134
33ART
20
9FKF
3
21VBC
24
Write program code to declare an instance of Train for each of the four trains.
Save your program.
Copy and paste the program code into part 2(b) in the evidence document.
[2]
(c) The class Station stores the data about the stations:
Station
StationID : String
stores the station ID
NumberPlatforms : Integer
stores the number of platforms at the station
Trains[0:9] : Train
stores the trains currently at the station platforms
NumberTrains : Integer
stores the number of trains currently at the station
platforms
initialises StationID and NumberPlatforms
Constructor()
to the parameter values, initialises Trains to an
empty array and NumberTrains to 0
GetTrains()
returns a string containing data about the trains
currently at the station platforms
takes a Train parameter and stores it if there is a
AddTrain()
platform available; each platform can only have one
train
Write program code to declare the class Station and its constructor.
(i)
Do not declare the other methods.
All attributes should be private.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program.
Copy and paste the program code into part 2(c)(i) in the evidence document.
[3]
The method AddTrain() takes a Train parameter. The method compares the
(ii)
attributes NumberTrains and NumberPlatforms to identify if there is a platform
available (a platform currently with no train).
The method returns FALSE if there are no platforms available.
If there is a platform available, the method:
•
stores the Train parameter in the array Trains
•
updates the appropriate attribute(s)
•
returns TRUE
Write program code for AddTrain()
Save your program.
Copy and paste the program code into part 2(c)(ii) in the evidence document.
[4]
The method GetTrains() returns the string "There are no trains" if there are no
(iii)
trains at the station platforms.
If there are trains at the station platforms, the method returns a string in the format:
The trains at station <StationID> are:
<TrainIDNumber> on route number <Route>
The line <TrainIDNumber> on route number <Route> is repeated for each train
at the station platforms.
For example: If the station with the station ID "NT1" has two trains with the train ID
numbers "48RTG", "6UFH", the method will produce this output:
The trains at station NT1 are:
48RTG on route number 43
6UFH on route number 12
Write program code for GetTrains()
Save your program.
Copy and paste the program code into part 2(c)(iii) in the evidence document.
[6]
(d) The program is tested with two stations:
number of
station ID
platforms
STH
2
NTH
1
Write program code to amend the main program to declare an instance of Station for
(i)
each of the two

5
9618/41/O/N/25 · Question 3Oct/Nov 2025Paper 4125 marks
Loading question…
Question text

A program stores records in the 2D array HashTable. Each record is stored at a specific index of
3
the array that is calculated using a hashing algorithm with the record’s key field.
The array has 100 × 10 elements. The hashing algorithm uses the key to generate an index
between 0 and 99 (inclusive). If two key fields generate the same index, there is a collision. Any
records that have a collision are stored in the next space in the same index.
For example: In this table two record keys generated the same hash value of 1. Four record keys
generated the same hash value of 3.
Index
0
1
2
3
4
5
…
9
0
record
1
record
record
2
3
record
record
record
record
4
…
99
The program uses Object-Oriented Programming (OOP).
(a) The class Record stores data about the records:
Record
Key : Integer
stores the integer key field for the data
Data : String
stores the string data
initialises Key and Data to its parameter values
Constructor()
The attributes Key and Data are public.
Write program code to declare the class Record and its constructor.
Use your programming language appropriate constructor.
Save your program as Question3_N25.
Copy and paste the program code into part 3(a) in the evidence document.
[2]
(b) The procedure InitialiseHashTable() initialises each element in the array to an empty
or null record.
Write program code to declare the global 2D array HashTable and the procedure
InitialiseHashTable()
Save your program.
Copy and paste the program code into part 3(b) in the evidence document.
[2]
(c) The function Hash():
•
takes an integer key field as a parameter
•
calculates and returns the hash value of the key field.
The hash value is the result from the formula: key MOD 100
Write program code for Hash()
Save your program.
Copy and paste the program code into part 3(c) in the evidence document.
[2]
(d) The procedure InsertData():
•
takes an object of type Record as a parameter
•
calculates the hash value for the parameter using the appropriate function
•
stores the parameter in the correct position in HashTable
You can assume there will be no more than 10 objects that generate the same hash value.
Write program code for InsertData()
Save your program.
Copy and paste the program code into part 3(d) in the evidence document.
[4]
(e) The file "HashTableData.txt" stores 200 key values and string data items in the format:
key,string
For example, the first row in the text file is:
528,permission
The key is 528 and the string data is "permission"
The procedure ReadData():
•
opens the text file and reads each line
•
splits each line into the key and data
•
calls InsertData() with an object containing each key and matching data.
Write program code for ReadData()
Save your program.
Copy and paste the program code into part 3(e) in the evidence document.
[5]
The function GetRecord():
(f)
•
takes an integer key field as a parameter
•
calculates the hash value for the key field using the appropriate function
•
searches the hash table for the record with the matching key field
•
returns the data for the record if the record is found
•
returns "Not found" if the record is not found.
Write program code for GetRecord()
Save your program.
Copy and paste the program code into part 3(f) in the evidence document.
[5]
(g) The main program:
•
calls InitialiseHashTable() and ReadData()
•
takes five integer key fields as input from the user
•
calls GetRecord() with each input and outputs the return value.
(i)
Write program code for the main program.
Save your program.
Copy and paste the program code into part 3(g)(i) in the evidence document.
[3]
(ii)
Test your program with the following five inputs in the order given:
528
1128
1828
1062
39
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot(s) into part 3(g)(ii) in the evidence document.
[2]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and

6
9618/42/O/N/25 · Question 1Oct/Nov 2025Paper 4228 marks
Loading question…
Question text

1
A program stores data about birds using Object-Oriented Programming (OOP).
The class Bird stores the data about the birds:
Bird
DistancePerHour : Real
stores the number of kilometres per hour (km/h) the bird
can fly (between 0.0 and 100.0 inclusive)
Species : String
stores the species of the bird, for example Pigeon
XPosition : Real
stores the current horizontal position of the bird
YPosition : Real
stores the current vertical position of the bird
Constructor()
initialises Species and DistancePerHour to the
parameter values; initialises XPosition and YPosition
to 500.0
GetPosition()
returns a string message that contains the horizontal and
vertical position of the bird
GetSpecies()
returns the species of the bird
Move()
takes a direction and number of minutes flying (between
0 and 500 inclusive) as parameters and updates the
appropriate horizontal or vertical position
Write program code to declare the class Bird and its constructor.
(a) (i)
Do not declare the other methods.
All attributes should be private.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question1_N25.
Copy and paste the program code into part 1(a)(i) in the evidence document.
[4]
The method GetSpecies() returns the species of the bird.
(ii)
Write program code for GetSpecies()
Save your program.
Copy and paste the program code into part 1(a)(ii) in the evidence document.
[2]
The method GetPosition() returns a string of the bird’s data in the format:
(iii)
"X = " & <XPosition> & " Y = " & <YPosition>
An example string for a bird is:
X = 500.0 Y = 250.0
Write program code for GetPosition()
Save your program.
Copy and paste the program code into part 1(a)(iii) in the evidence document.
[3]
(iv)
If the bird is travelling north, the vertical position increases. If the bird is travelling south,
the vertical position decreases.
If the bird is travelling east, the horizontal position increases. If the bird is travelling west,
the horizontal position decreases.
The method Move():
•
takes the direction of travel as a parameter in the form ‘N’ for north, ‘S’ for south,
‘E’ for east or ‘W’ for west
•
takes the number of minutes that the bird has been flying (to the nearest minute) as
a parameter
•
calculates the distance travelled by the bird using the formula:
distance travelled = (distance per hour / 60) * minutes flying
•
updates the vertical or horizontal position using the distance calculated.
You do not need to validate the parameters.
Write program code for Move()
Save your program.
Copy and paste the program code into part 1(a)(iv) in the evidence document.
[5]
(b) The main program creates two instances of Bird
The first bird is the species ‘Cockatiel’ and flies 71.0 km/h.
The second bird is the species ‘Macaw’ and flies 56.0 km/h.
Write program code to declare and initialise the two birds.
Save your program.
Copy and paste the program code into part 1(b) in the evidence document.
[3]
(c) (i)
The main program needs to:
•
output a message that includes the species and current X position and Y position for
each bird
•
prompt the user to select one of the birds to move and take this as an input
•
prompt the user to enter the direction the bird has been travelling and take this as
an input
•
prompt the user to enter the time to the nearest minute that the bird has been
travelling and take this as an input
•
call the appropriate method to update the chosen bird’s position
•
output an update on the bird’s new position.
Each input needs to repeat until valid data is entered. All outputs must be meaningful.
Write program code to amend the main program.
Save your program.
Copy and paste the program code into part 1(c)(i) in the evidence document.
[8]
(ii)
Test your program four times to meet these criteria:
Test 1: The Cockatiel travels north for 60 minutes.
Test 2: The Macaw travels south for 30 minutes.
Test 3:

7
9618/43/O/N/25 · Question 1Oct/Nov 2025Paper 4331 marks
Loading question…
Question text

1
A program stores data for a board game using Object-Oriented Programming (OOP). The game
has objects that are placed on the board. Each object has a string code (for example "A") and an
integer value (for example, 2).
The class BoardObject stores the data about the objects that can be placed on the board:
BoardObject
Code : String
stores the board object’s code
Value : Integer
stores the integer value of the board object
Constructor()
initialises the attributes to the parameter values
GetCode()
returns Code
GetValue()
returns Value
Write program code to declare the class BoardObject and its constructor.
(a) (i)
Do not declare the other methods.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question1_N25.
Copy and paste the program code into part 1(a)(i) in the evidence document.
[5]
The methods GetCode() and GetValue() return the appropriate attribute.
(ii)
Write program code for GetCode() and GetValue()
Save your program.
Copy and paste the program code into part 1(a)(ii) in the evidence document.
[3]
(iii)
The table shows the code and value of five board objects. The table has the variable
identifier where each of the objects are stored.
Variable
Code
Value
identifier
Object1
"A"
2
Object2
"B"
3
Object3
"C"
5
Object4
"D"
2
Object5
"E"
7
Write program code for the main program to instantiate each of the five board objects
and store them in the variables with the identifiers given.
Save your program.
Copy and paste the program code into part 1(a)(iii) in the evidence document.
[3]
(b) The board objects are placed on a board that is represented by a 0-indexed 2D array:
•
the board is a 10 x 10 grid
•
each position on the board is identified by a row and column number
•
rows are numbered 0 to 9
•
columns are numbered 0 to 9
•
board objects can be placed at a row and column position
•
each board position is initialised with an empty BoardObject, an empty BoardObject
has Code = "-" and Value = 0
For example, the element highlighted in the given board is in row 1 and column 3.
Row
Column
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
The class Board stores the data about the board and where the board objects are placed.
Board
TheBoard : ARRAY[0:9, 0:9] of BoardObject
stores the board contents as a 2D array of
10 x 10 elements of type BoardObject
Constructor()
initialises each of TheBoard elements to
an empty BoardObject with Code = "-"
and Value = 0
GetObject()
takes a row and column number as
parameters and returns the BoardObject
at the row, column position
SetObject()
takes a BoardObject, row number and
column number as parameters. Stores the
BoardObject in TheBoard at the given
row, column position
DisplayBoard()
outputs the code of each BoardObject
stored in TheBoard, one row at a time
Write program code to declare the class Board and its constructor.
(i)
Do not declare the other methods.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program.
Copy and paste the program code into part 1(b)(i) in the evidence document.
[4]
The method GetObject() takes a row number and column number as parameters.
(ii)
The method returns the BoardObject stored at the parameter position.
Write program code for GetObject()
Save your program.
Copy and paste the program code into part 1(b)(ii) in the evidence document.
[2]
The method SetObject() takes three parameters: a BoardObject, row number and
(iii)
column number.
The method stores the BoardObject parameter in the row, column position in
TheBoard
Write program code for SetObject()
Save your program.
Copy and paste the program code into part 1(b)(iii) in the evidence document.
[2]
The method DisplayBoard() outputs the Code of each BoardObject stored in
(iv)
TheBoard using GetCode()
Each row in TheBoard is output on one li

8
9618/41/M/J/25 · Question 3May/June 2025Paper 4130 marks
Loading question…
Question text

3
A program stores data in a binary tree that is designed using Object‑Oriented Programming
(OOP).
The tree stores data in ascending numerical order, for example:
30
20
45
1
21
33
63
The class Node stores data about the nodes.
Node
NodeData : Integer
stores the node’s integer data
LeftNode : Node
stores the node that is stored to the left of the current
node, or a null value if there is no node to the left
RightNode : Node
stores the node that is stored to the right of the current
node, or a null value if there is no node to the right
Constructor()
initialises NodeData to its parameter value; initialises
LeftNode and RightNode to a null value
GetLeft()
returns LeftNode
GetRight()
returns RightNode
GetData()
returns NodeData
SetLeft()
takes an object of type Node as a parameter and stores
it in LeftNode
SetRight()
takes an object of type Node as a parameter and stores
it in RightNode
Write program code to declare the class Node and its constructor.
(a) (i)
Do not declare the other methods.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question3_J25.
Copy and paste the program code into part 3(a)(i) in the evidence document.
[4]
(ii)
Write program code for the three get methods.
Save your program.
Copy and paste the program code into part 3(a)(ii) in the evidence document.
[3]
The method SetLeft() takes an object of type Node as a parameter. The method
(iii)
stores the parameter in the attribute LeftNode
The method SetRight() takes an object of type Node as a parameter. The method
stores the parameter in the attribute RightNode
Write program code for SetLeft() and SetRight()
Save your program.
Copy and paste the program code into part 3(a)(iii) in the evidence document.
[3]
(b) Write the main program to declare five objects of type Node :
•
Node 1 with the data 10
•
Node 2 with the data 20
•
Node 3 with the data 5
•
Node 4 with the data 15
•
Node 5 with the data 7
Save your program.
Copy and paste the program code into part 3(b) in the evidence document.
[2]
(c) The class Tree stores the tree.
Tree
FirstNode : Node
stores the root node in the tree
Constructor()
initialises FirstNode to its parameter value
GetRootNode()
returns the node stored in FirstNode
Insert()
stores its parameter node in the correct position in the
tree
Write program code to declare the class Tree and its constructor.
(i)
Do not declare the other methods.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program.
Copy and paste the program code into part 3(c)(i) in the evidence document.
[2]
Write program code for GetRootNode()
(ii)
Save your program.
Copy and paste the program code into part 3(c)(ii) in the evidence document.
[1]
The method Insert() takes a node as a parameter and then searches the tree to find
(iii)
the position to insert the new node by:
•
checking whether the node’s data is less than or greater than the root node’s data
•
moving to the left node if the data is less than the root node’s data
•
moving to the right node if the data is greater than or equal to the root node’s data
•
repeating until the final position of the node is found and stores the node in that
position.
Write program code for Insert()
Save your program.
Copy and paste the program code into part 3(c)(iii) in the evidence document.
[6]
(d) The recursive procedure OutputInOrder() outputs the data stored in the binary tree in
ascending numerical order.
The procedure takes a Node object as a parameter and then:
•
checks if the left node is null. If there is a left node, the function calls itself with the left
node
•
outputs the data of the current node
•
checks if the right node is null. If there is a right node, the function calls itself with the
right node.
Write program code for OutputInOrder()
Save your program.
Copy an

Advertisement
9
9618/42/M/J/25 · Question 3May/June 2025Paper 4226 marks
Loading question…
Question text

3
A program stores data about animals using Object‑Oriented Programming (OOP).
The class Animal stores the data about animals.
Animal
Name : String
stores the name of the animal
Sound : String
stores the sound the animal makes
Size : Integer
stores the size of the animal as an integer between 1 (smallest)
and 10 (largest)
Intelligence : Integer
stores the intelligence of the animal as an integer between 1 (least)
and 10 (most)
Constructor()
initialises all attributes to its parameter values
Description()
returns a string message that contains the data from the attributes
Write program code to declare the class Animal and its constructor.
(a) (i)
Do not declare the other methods.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question3_J25.
Copy and paste the program code into part 3(a)(i) in the evidence document.
[4]
The method Description() creates and returns a string of the animal’s data in the
(ii)
format:
"The animal's name is " <Name> ", it makes a " <Sound> ", its size
is " <Size> " and its intelligence level is " <Intelligence>
For example:
The animal's name is Teddy, it makes a Bark, its size is 4 and its
intelligence level is 6
Write program code for Description()
Save your program.
Copy and paste the program code into part 3(a)(ii) in the evidence document.
[3]
(b) The class Parrot inherits from the class Animal
Parrot inherits the attributes from Animal and overrides the Description() method. The
additional attributes and methods in the class Parrot are:
Parrot
WingSpan : Integer
the width of the parrot’s wings to the nearest cm
NumberWords : Integer
the number of words the parrot can speak
Constructor()
calls the parent constructor using its parameter values;
initialises WingSpan and NumberWords to its parameter values
ChangeNumberWords()
takes an integer parameter and adds this to the number currently
in NumberWords
Write program code to declare the class Parrot, its constructor and the method
(i)
ChangeNumberWords()
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program.
Copy and paste the program code into part 3(b)(i) in the evidence document.
[4]
The method Description() in the class Parrot creates and returns a string of the
(ii)
animal’s data in the format:
"The animal's name is " <Name> ", it makes a " <Sound> ", its size
is " <Size> " and its intelligence level is " <Intelligence> ". It
has a wingspan of " <WingSpan> "cm and can say " <NumberWords> "
words."
For example:
The animal's name is Chewie, it makes a Squawk, its size is 1 and
its intelligence level is 10. It has a wingspan of 30cm and can
say 29 words.
Write program code for Description()
Save your program.
Copy and paste the program code into part 3(b)(ii) in the evidence document.
[2]
(c) The class Wolf inherits from the class Animal
Wolf inherits the attributes from Animal and overrides the Description() method. The
additional attributes and methods in the class Wolf are:
Wolf
TerritorySize : Integer
stores the size of the area where the wolf lives, to the nearest
square mile
Constructor()
calls the parent constructor using its parameter values;
initialises TerritorySize to its parameter value
SetTerritorySize()
takes an integer parameter and adds this to the number currently
in TerritorySize
Write program code to declare the class Wolf, its constructor and the method
(i)
SetTerritorySize()
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program.
Copy and paste the program code into part 3(c)(i) in the evidence document.
[4]
The method Description() in the class Wolf creates and returns a string of the
(ii)
animal’s data in the format:
"The animal's name is " <Name> ", it makes a " <Sound> ", its size
is " <Size

10
9618/43/M/J/25 · Question 3May/June 2025Paper 4329 marks
Loading question…
Question text

3
A program stores data in a linked list that is designed using Object‑Oriented Programming (OOP).
The class Node stores data about the nodes.
Node
TheData : Integer
stores the integer data
NextNode : Node
stores the next node in the linked list
Constructor()
initialises TheData to its parameter value, initialises NextNode
to a null value
GetData()
returns TheData
GetNextNode()
returns NextNode
SetNextNode()
takes an object of type Node as a parameter and stores it in
NextNode
Write program code to declare the class Node and its constructor.
(a) (i)
Do not declare the other methods.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question3_J25.
Copy and paste the program code into part 3(a)(i) in the evidence document.
[4]
(ii)
Write program code for the two get methods.
Save your program.
Copy and paste the program code into part 3(a)(ii) in the evidence document.
[3]
The method SetNextNode() takes an object of type Node as a parameter. The method
(iii)
stores the parameter in the attribute NextNode
Write program code for SetNextNode()
Save your program.
Copy and paste the program code into part 3(a)(iii) in the evidence document.
[2]
(b) The class LinkedList stores the linked list.
LinkedList
HeadNode : Node
stores the first node in the linked list
Constructor()
initialises HeadNode to a null value
InsertNode()
creates a new node using its integer parameter. Sets this
node as the new head node and updates NextNode
RemoveNode()
finds the first node that contains its integer parameter and
removes this node from the linked list
Traverse()
concatenates and returns the integer data in each node in
the linked list
Write program code to declare the class LinkedList and its constructor.
(i)
Do not declare the other methods.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program.
Copy and paste the program code into part 3(b)(i) in the evidence document.
[2]
The method InsertNode():
(ii)
•
takes an integer as a parameter
•
creates a new node with the parameter as the integer data
•
uses the new node’s method SetNextNode() to store the current HeadNode as
the next node
•
replaces HeadNode with the current node.
Write program code for InsertNode()
Save your program.
Copy and paste the program code into part 3(b)(ii) in the evidence document.
[4]
The method Traverse() concatenates the integer data from the nodes in the linked
(iii)
list, starting with the node stored in HeadNode. The method returns the final string with
each integer data separated with a space.
Write program code for Traverse()
Save your program.
Copy and paste the program code into part 3(b)(iii) in the evidence document.
[3]
The method RemoveNode() takes an integer parameter to search for and remove from
(iv)
the linked list.
The method first checks if the linked list is empty. If the linked list is empty the method
returns FALSE
If the linked list is not empty, the integer data in HeadNode is compared to the parameter.
If it matches the parameter, HeadNode is changed to store the next node.
If the parameter does not match, the nodes are followed until either:
•
the node with matching integer data is found. This node is removed, the appropriate
nodes updated and TRUE returned
or
•
none of the nodes contain matching integer data to the parameter. No nodes are
removed and FALSE is returned.
Write program code for RemoveNode()
Save your program.
Copy and paste the program code into part 3(b)(iv) in the evidence document.
[6]
The main program creates a new LinkedList object and uses the appropriate method
(c) (i)
to insert five nodes with the following integer data values in the order given:
10
20
30
40
50
The main program then:
•
calls Traverse()
•
removes the node containing the integer data 30 using Remov

11
9618/41/O/N/24 · Question 2Oct/Nov 2024Paper 4134 marks
Loading question…
Question text

2
A computer program is designed to simulate horses doing show jumping. In show jumping, horses
jump over obstacles called fences. A horse successfully jumps a fence if it does not knock the
fence down.
The program is written using Object-Oriented Programming (OOP).
The class Horse stores data about the horses.
Horse
Name : STRING
stores the name given to the horse
MaxFenceHeight : INTEGER
stores the maximum height in cm that the horse can
jump, for example 132
PercentageSuccess : INTEGER
stores the percentage chance of a horse not knocking
down a fence, for example 70 represents a 70% chance
of jumping a fence successfully
initialises Name, MaxFenceHeight and
Constructor()
PercentageSuccess to its parameter values
GetName()
returns the name of the horse
GetMaxFenceHeight()
returns the maximum height the horse can jump
Success()
calculates and returns the percentage chance of a horse
successfully jumping a specific fence
Write program code to declare the class Horse and its constructor.
(a) (i)
Do not declare the other methods.
Use your programming language’s appropriate constructor.
All attributes must be private. If you are writing in Python, include attribute declarations
using comments.
Save your program as Question2_N24.
Copy and paste the program code into part 2(a)(i) in the evidence document.
[4]
The get methods GetName() and GetMaxFenceHeight() each return the relevant
(ii)
attribute.
Write program code for the get methods.
Save your program.
Copy and paste the program code into part 2(a)(ii) in the evidence document.
[3]
(b) The array Horses stores objects of type Horse.
(i)
The program has two horses:
•
The horse named ‘Beauty’ can jump a maximum height of 150 cm and has a success
percentage rate of 72%.
•
The horse named ‘Jet’ can jump a maximum height of 160 cm and has a success
percentage rate of 65%.
Write program code to:
•
declare the array, Horses, local to the main program with space for two Horse
objects
•
store the two horses described in the array
•
output the name of both Horse objects from the array.
Save your program.
Copy and paste the program code into part 2(b)(i) in the evidence document.
[5]
(ii)
Test your program.
Take a screenshot of the output.
Save your program.
Copy and paste the screenshot into part 2(b)(ii) in the evidence document.
[1]
(c) The class Fence stores data about the fences. Each fence has a height in cm and a risk
number.
The risk is a whole number between 1 and 5 inclusive. A risk of 1 means the fence is the
easiest type to jump. A risk of 5 means the fence is the hardest type to jump.
Fence
Height : INTEGER
stores the height of the fence in cm
the height is between 70 and 180 inclusive
Risk : INTEGER
stores the risk as a whole number between 1 and 5
inclusive
initialises Height and Risk to its parameter values
Constructor()
GetHeight()
returns the height of the fence
GetRisk()
returns the risk of the fence
Write program code to declare the class Fence, its constructor and get methods.
(i)
Use your programming language’s appropriate constructor.
All attributes must be private.
If you are writing in Python, include attribute declarations using comments.
Save your program.
Copy and paste the program code into part 2(c)(i) in the evidence document.
[4]
The array Course stores four Fence objects. The user inputs the height and risk for
(ii)
each fence, and these are validated before each fence is created.
Amend the main program to:
•
declare the local array Course
•
take as input the data for four fences from the user
•
loop the input until both the height and risk are valid for each fence
•
create an instance of Fence for each of the four valid fences and store each
instance in the array.
Save your program.
Copy and paste the program code into part 2(c)(ii) in the evidence document.
[5]
(d) The chance of a horse jumping a fence without knocking it down is calculated as follows.
If the height of the fence is more than the maxi

12
9618/42/O/N/24 · Question 1Oct/Nov 2024Paper 4229 marks
Loading question…
Question text

1
A computer game is designed for users to select characters. Each character can take part in a
group of events. Each group has five events. There are four types of event: jump, swim, run, drive.
The program is written using object-oriented programming.
(a) The class EventItem stores data about the events.
EventItem
EventName : STRING
stores the name of the event
Type : STRING
stores the type of event, either: jump, swim, run or drive
Difficulty : INTEGER
stores the difficulty of the event from 1 (easiest) to 5
(hardest)
Constructor()
initialises EventName, Type and Difficulty to its
parameter values
GetName()
returns the name of the event
GetDifficulty()
returns the difficulty of the event
GetEventType()
returns the type of event
Write program code to declare the class EventItem and its constructor.
(i)
Do not declare the other methods.
Use your programming language’s appropriate constructor.
All attributes must be private.
If you are writing in Python, include attribute declarations, using comments.
Save your program as Question1_N24.
Copy and paste the program code into part 1(a)(i) in the evidence document.
[4]
The get methods GetName(), GetDifficulty() and GetEventType() each return
(ii)
the relevant attribute.
Write program code for the three get methods.
Save your program.
Copy and paste the program code into part 1(a)(ii) in the evidence document.
[3]
(b) The array Group stores five objects of type EventItem.
Write program code to declare Group local to the main program.
(i)
Save your program.
Copy and paste the program code into part 1(b)(i) in the evidence document.
[1]
(ii)
One group has the following events:
Event name
Event type
Event difficulty
Bridge
jump
3
Water wade
swim
4
100 mile run
run
5
Gridlock
drive
2
Wall on wall
jump
4
Write program code to create an instance of EventItem for each of the five events, and
store them in Group.
Save your program.
Copy and paste the program code into part 1(b)(ii) in the evidence document.
[3]
(c) The class Character stores data about the characters in the game.
Each character has a skill level for each type of event. The skill level is an integer between
1 and 5 inclusive. Skill level 1 is the lowest skill level, and skill level 5 is the highest skill level.
Character
CharacterName : STRING
stores the name of the character
Jump : INTEGER
stores the character’s skill level at events of type jump
Swim : INTEGER
stores the character’s skill level at events of type swim
Run : INTEGER
stores the character’s skill level at events of type run
Drive : INTEGER
stores the character’s skill level at events of type drive
Constructor()
initialises CharacterName, Jump, Swim, Run and
Drive to its parameter values
GetName()
returns the name of the character
CalculateScore()
takes the type of event and difficulty as parameters.
Calculates and returns the chance of the character
completing the event
Write program code to declare the class Character, its constructor and get method.
Use your programming language’s appropriate constructor.
All attributes must be private.
If you are writing in Python, include attribute declarations, using comments.
Save your program.
Copy and paste the program code into part 1(c) in the evidence document.
[4]
(d) The method CalculateScore() in the Character class calculates and returns the
percentage chance of a character completing an event.
When a character’s skill level is greater than or equal to the difficulty of that event, the
percentage chance of completing the event is 100%.
When a character’s skill level is less than the difficulty of that event, the character’s skill level
is subtracted from the difficulty of that event. This difference is used to identify the percentage
chance of success using this table:
Percentage chance
Difference
of success
1
80
2
60
3
40
4
20
For example:
•
A character has a skill level of 3 for events of type run.
•
An event of type run has a difficulty level of 5
•
The

13
9618/41/M/J/24 · Question 2May/June 2024Paper 4131 marks
Loading question…
Question text

2
A computer program will store data about trees.
The user can enter their requirements for a tree and a suitable tree will be selected.
The program is written using object‑oriented programming.
The class Tree stores data about the trees.
Tree
TreeName : STRING
stores the name of the tree
HeightGrowth : INTEGER
stores the number of cm the tree will grow each year
MaxHeight : INTEGER
stores the maximum height in cm that the tree will grow
MaxWidth : INTEGER
stores the maximum width in cm that the tree will grow
Evergreen : STRING
stores whether the tree keeps its leaves as "Yes", or
loses its leaves as "No"
Constructor()
initialises TreeName, HeightGrowth, MaxHeight,
MaxWidth and Evergreen to its parameter values
GetTreeName()
returns the name of the tree
GetGrowth()
returns the number of cm the tree will grow each year
GetMaxHeight()
returns the maximum height in cm that the tree will grow
GetMaxWidth()
returns the maximum width in cm that the tree will grow
GetEvergreen()
returns whether the tree keeps its leaves or loses its
leaves
Write program code to declare the class Tree and its constructor.
(a) (i)
Do not declare the other methods.
Use the appropriate constructor for your programming language.
All attributes must be private.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question2_J24.
Copy and paste the program code into part 2(a)(i) in the evidence document.
[4]
The get methods GetTreeName(), GetGrowth(), GetMaxHeight(),
(ii)
GetMaxWidth() and GetEvergreen() each return the relevant attribute.
Write program code for the get methods.
Save your program.
Copy and paste the program code into part 2(a)(ii) in the evidence document.
[3]
(b) The text file Trees.txt stores data about 9 trees.
The data in the file is stored in the format:
Tree name,Height growth each year,Maximum height,Maximum width,Evergreen
For example, the first row of data is:
Beech,30,400,200,No
The tree is a Beech. It can grow 30 cm each year. It has a maximum height of 400 cm.
It has a maximum width of 200 cm. It is not evergreen (it loses its leaves).
The function ReadData():
•
creates an array of type Tree
•
reads the data from the file
•
raises an exception if the file is not found
•
creates a new object of type Tree for each tree in the file
•
appends each object to the array
•
returns the array.
Write program code for ReadData().
Save your program.
Copy and paste the program code into part 2(b) in the evidence document.
[7]
(c) The procedure PrintTrees() takes a Tree object as a parameter and outputs the tree’s
name, height growth each year, maximum height, maximum width and whether it is evergreen.
The output message changes depending on whether it is evergreen.
If it is evergreen, it is in the format:
TreeName has a maximum height MaxHeight a maximum width MaxWidth and grows
HeightGrowth cm a year. It does not lose its leaves.
If it is not evergreen, it is in the format:
TreeName has a maximum height MaxHeight a maximum width MaxWidth and grows
HeightGrowth cm a year. It loses its leaves each year.
Write program code for PrintTrees().
Save your program.
Copy and paste the program code into part 2(c) in the evidence document.
[4]
(d) The main program calls ReadData(), stores the return value and calls PrintTrees() with
the first object in the returned array.
(i)
Write program code for the main program.
Save your program.
Copy and paste the program code into part 2(d)(i) in the evidence document.
[2]
(ii)
Test your program.
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into part 2(d)(ii) in the evidence document.
[1]
(e) The procedure ChooseTree() takes an array of Tree objects as a parameter.
The procedure prompts the user to input their requirements for a tree.
The user needs to enter:
•
the maximum height the tree can be in cm
•
the maximum width the tree can be in cm
•
whether they want the tree to

Advertisement
14
9618/42/M/J/24 · Question 2May/June 2024Paper 4230 marks
Loading question…
Question text

2
A binary tree stores data in ascending order. For example:
15
8
19
3
10
A computer program stores integers in a binary tree in ascending order. The program uses
Object‑Oriented Programming (OOP).
The binary tree is stored as a 1D array of nodes. Each node contains a left pointer, a data value
and a right pointer.
The class Node stores the data about a node.
Node
LeftPointer : INTEGER
stores the index of the node to the left in the binary tree
Data : INTEGER
stores the node’s data
RightPointer : INTEGER
stores the index of the node to the right in the binary tree
Constructor()
initialises Data to its parameter value
initialises LeftPointer and RightPointer to −1
GetLeft()
returns the left pointer
GetRight()
returns the right pointer
GetData()
returns the data value
SetLeft()
assigns the parameter to the left pointer
SetRight()
assigns the parameter to the right pointer
SetData()
assigns the parameter to the data
Write program code to declare the class Node and its constructor.
(a) (i)
Do not declare the other methods.
Use the appropriate constructor for your programming language.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question2_J24.
Copy and paste the program code into part 2(a)(i) in the evidence document.
[4]
The get methods GetLeft(), GetRight()and GetData()each return the relevant
(ii)
attribute.
Write program code for the three get methods.
Save your program.
Copy and paste the program code into part 2(a)(ii) in the evidence document.
[3]
The set methods SetLeft(), SetRight()and SetData()each take a parameter and
(iii)
then store this in the relevant attribute.
Write program code for the three set methods.
Save your program.
Copy and paste the program code into part 2(a)(iii) in the evidence document.
[3]
(b) The class TreeClass stores the data about the binary tree.
TreeClass
Tree[0:19] : Node
an array of 20 elements of type Node
FirstNode : INTEGER
stores the index of the first node in the tree
NumberNodes : INTEGER
stores the quantity of nodes in the tree
Constructor()
initialises FirstNode to −1 and NumberNodes to 0
initialises each element in Tree to a Node object with the
data value of −1
InsertNode()
takes a Node object as a parameter, inserts it in the array
and updates the pointer for its parent node
OutputTree()
outputs the left pointer, data and right pointer of each
node in Tree
Nodes cannot be deleted from this tree.
Write program code to declare the class TreeClass and its constructor.
(i)
Do not declare the other methods.
Use the appropriate constructor for your programming language.
If you are writing in Python, include attribute declarations using comments.
Save your program.
Copy and paste the program code into part 2(b)(i) in the evidence document.
[4]
The method InsertNode()takes a Node object, NewNode, as a parameter and inserts
(ii)
it into the array Tree.
InsertNode()first checks if the tree is empty.
If the tree is empty, InsertNode():
•
stores NewNode in the array Tree at index NumberNodes
•
increments NumberNodes
•
stores 0 in FirstNode.
If the tree is not empty, InsertNode():
•
stores NewNode in the array Tree at index NumberNodes
•
accesses the data in the array Tree at index FirstNode and compares it to the
data in NewNode
•
repeatedly follows the pointers until the correct position for NewNode is found
•
once the position is found, InsertNode()sets the left or right pointer of its parent
node
•
increments NumberNodes.
Write program code for InsertNode().
Save your program.
Copy and paste the program code into part 2(b)(ii) in the evidence document.
[6]
The method OutputTree()outputs the left pointer, the data and the right pointer for
(iii)
each node that has been inserted into the tree. The outputs are in the order they are
saved in the array.
If there are no nodes in the array, the procedure outputs ‘No nodes’.
Write program code for OutputTree().
Save your program.
Copy and paste the progra

15
9618/41/O/N/23 · Question 3Oct/Nov 2023Paper 4130 marks
Loading question…
Question text

3
A computer game is written using object-oriented programming.
The game has multiple characters that can move around the screen.
The class Character stores data about the characters. Each character has a name, a current X
(horizontal) position and a current Y (vertical) position.
Character
Name : STRING
stores the name of the character as a string
XPosition : INTEGER
stores the X position as an integer
YPosition : INTEGER
stores the Y position as an integer
Constructor()
initialises Name, XPosition and YPosition to its
parameter values
GetXPosition()
returns the X position
GetYPosition()
returns the Y position
SetXPosition()
adds the parameter to the X position
validates that the new X position is between 0 and 10 000
inclusive
SetYPosition()
adds the parameter to the Y position
validates that the new Y position is between 0 and 10 000
inclusive
Move()
takes a direction as a parameter and calls either
SetXPosition or SetYPosition with an integer value
(a) (i)
Write program code to declare the class Character and its constructor.
Do not declare the other methods.
Use your programming language’s appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question3_N23.
Copy and paste the program code into part 3(a)(i) in the evidence document.
[4]
(ii)
The get methods GetXPosition() and GetYPosition() each return the relevant
attribute.
Write program code for the get methods.
Save your program.
Copy and paste the program code into part 3(a)(ii) in the evidence document.
[3]
(iii)
The set methods SetXPosition() and SetYPosition() each take a value as a
parameter and add this to the current X or Y position.
If the new value exceeds 10 000, it is limited to 10 000.
If the new value is below 0, it is limited to 0.
Write program code for the set methods.
Save your program.
Copy and paste the program code into part 3(a)(iii) in the evidence document.
[4]
(iv)
The method Move() takes a string parameter: "up", "down", "left" or "right".
The table shows the change each direction will make to the X or Y position.
Use the appropriate method to change the position value.
Direction
Value change
up
Y position + 10
down
Y position − 10
left
X position − 10
right
X position + 10
Write program code for Move().
Save your program.
Copy and paste the program code into part 3(a)(iv) in the evidence document.
[4]
(b) Write program code to declare a new instance of Character with the identifier Jack.
The starting X position is 50 and the starting Y position is 50, the character’s name is Jack.
Save your program.
Copy and paste the program code into part 3(b) in the evidence document.
[2]
(c) The class BikeCharacter inherits from the class Character.
BikeCharacter
Constructor()
takes Name, XPosition and YPosition as parameters
calls its parent class constructor with the appropriate values
Move()
overrides the method Move() from the parent class by
changing either the X position or the Y position by 20
instead of 10
(i)
Write program code to declare the class BikeCharacter and its constructor.
Do not declare the other method.
Use your programming language’s appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program.
Copy and paste the program code into part 3(c)(i) in the evidence document.
[3]
(ii)
The method Move() overrides the method from the parent class.
The table shows the change each direction will make to the X or Y position.
Direction
Value change
up
Y position + 20
down
Y position − 20
left
X position − 20
right
X position + 20
Write program code for Move().
Save your program.
Copy and paste the program code into part 3(c)(ii) in the evidence document.
[2]
(d) Write program code to declare a new instance of BikeCharacter with the identifier Karla.
The starting X position is 100, the starting Y position is 50 and the character’s name is Karla.
Save your program.
Copy and paste the

Advertisement