OOPs With Inheritance - Character and Magic Character
OOPs With Inheritance - Character and Magic Character
The class Character stores data about the game characters. Each character has a name,
date of birth, intelligence value and speed value.
(a) (i) Write program code to declare the class Character and its constructor.
Do not declare the other methods.
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.
Output the name, age and intelligence of the character in an appropriate message.
Save your program.
Copy and paste the program code into part 2(b)(ii) in the evidence document.
[3]
(iii) Test your program. Take a screenshot of the output.
Save your program.
Copy and paste the screenshot into part 2(b)(iii) in the evidence document.
[1]
(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.
(i) Write program code to declare the class MagicCharacter and its constructor.
(ii) The method Learn() overrides the parent class method and increases the
intelligence depending on the character’s element.
(d) (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.
Save your program.
Copy and paste the program code into part 2(d)(i) in the evidence document.
[2]
(ii) 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.
Save your program.
Copy and paste the program code into part 2(d)(ii) in the evidence document.
[1]
(iii) Test your program. Take a screenshot of the output.
Save your program.
Copy and paste the screenshot into part 2 (d)(iii) in the evidence document.
[1]