Oop Questions
Oop Questions
The game has multiple characters that can move around the screen.
(a) 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
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
(i) Write program code to declare the class Character and its constructor.
If you are writing in Python, include attribute declarations using comments. [4]
(ii) The get methods GetXPosition() and GetYPosition() each return the relevant
attribute.
(iii) The set methods SetXPosition() and SetYPosition() each take a value as a parameter and add
this to the current X or Y position.
(b) 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.
up Y position + 10
down Y position − 10
left X position − 10
right X position + 10
(v) 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.
[2]
BikeCharacter
Write program code to declare the class BikeCharacter and its constructor.
If you are writing in Python, include attribute declarations using comments. [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.
up Y position + 20
down Y position − 20
left X position − 20
right X position + 20
(iii) 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.
4
(a) The class Character stores data about the game characters. Each character has a name, date of
birth, intelligence value and speed value.
Character
(i) Write program code to declare the class Character and its constructor.
If you are writing in Python, include attribute declarations using comments. [5]
(ii) The get methods GetIntelligence() and GetName() return the attribute values.
Write program code for the methods GetIntelligence() and GetName(). [3]
(iii) The method SetIntelligence() assigns the value of its parameter to the attribute.
(iv ) The method Learn() increases the current value of Intelligence by 10%.
5
(v) The method ReturnAge() calculates and returns the age of the character in years as an integer.
Assume that the current year is 2023 and only use the year from the date of birth for the
calculation. For example, the method returns 18 if the character was born on any date in 2005.
(b) (i) Write program code to create a new instance of Character with the identifier FirstCharacter.
The name of the character is Royal, date of birth is 1 January 2019, intelligence is 70 and speed is
30. [2]
(ii) Write program code to call the method Learn() for the character created in part 3(b)(i).
Output the name, age and intelligence of the character in an appropriate message. [3]
(c) The class MagicCharacter inherits from the class Character. A magic character has an element,
for example, water. This element changes how they learn. The magic character’s element is
stored in the additional attribute Element.
MagicCharacter
(i) Write program code to declare the class MagicCharacter and its constructor.
If you are writing in Python, include attribute declarations using comments. [5]
() The method Learn() overrides the parent class method and increases the intelligence depending on
the character’s element.
If the element is not fire, water or earth the intelligence increases by 10%.
(i) Write program code to create a new instance of MagicCharacter with the identifier
FirstMagic.
The name of the character is Light, date of birth is 3 March 2018, intelligence is 75, speed
is 22 and element is fire.
Copy and paste the program code into part 3(d)(i) in the evidence document.
[2]
Write program code to call the method Learn() for the character created in part 3(d)(i).
Output the name, age and intelligence of the character in an appropriate message.
Copy and paste the program code into part 3(d)(ii) in the evidence document.
[1]
The end