A computer game is written using object-oriented programming. The game has multiple characters. The class Character stores data about the game characters. Each character has a name, date of birth, intelligence value and speed value. Character CharacterName : STRING stores the name of the character DateOfBirth : DATE stores the date of birth of the character Intelligence : REAL stores the intelligence value of the character Speed : INTEGER stores the speed value of the character Constructor() initialises CharacterName, DateOfBirth, Intelligence and Speed to the parameter values SetIntelligence() assigns the value of the parameter to Intelligence GetIntelligence() returns the value of Intelligence GetName() returns the name of the character ReturnAge () calculates and returns the age of the character as an integer Learn() increases the value of Intelligence by 10%
- (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.[5]
- (a)(ii)The get methods GetIntelligence() and GetName() return the attribute values. Write program code for the methods GetIntelligence() and GetName(). Save your program. Copy and paste the program code into part 3(a)(ii) in the evidence document.[3]
- (a)(iii)The method SetIntelligence() assigns the value of its parameter to the attribute. Write program code for SetIntelligence(). Save your program. Copy and paste the program code into part 3(a)(iii) in the evidence document.[2]
- (a)(iv)The method Learn() increases the current value of Intelligence by 10%. Write program code for Learn(). Save your program. Copy and paste the program code into part 3(a)(iv) in the evidence document.[1]
- (a)(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. Write program code for the method ReturnAge(). Save your program. Copy and paste the program code into part 3(a)(v) in the evidence document.[2]
- (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. Save your program. Copy and paste the program code into part 3(b)(i) in the evidence document.[2]
- (b)(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. Save your program. Copy and paste the program code into part 3(b)(ii) in the evidence document.[3]
- (b)(iii)Test your program. Take a screenshot of the output. Save your program. Copy and paste the screenshot into part 3(b)(iii) in the evidence document.[1]
- (c)(i)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 Element : STRING stores the element for the character Constructor() takes Element, CharacterName, DateOfBirth, Intelligence and Speed as parameters calls its parent class constructor with the appropriate values initialises Element to its parameter value Learn () alters the intelligence of the character depending on the character's element Write program code to declare the class MagicCharacter 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.[5]
- (c)(ii)The method Learn() overrides the parent class method and increases the intelligence depending on the character's element. • If the element is fire or water, intelligence increases by 20%. • If the element is earth, intelligence increases by 30%. • If the element is not fire, water or earth the intelligence increases by 10%. Write program code for Learn(). Save your program. Copy and paste the program code into part 3(c)(ii) in the evidence document.[3]
- (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 3(d)(i) in the evidence document.[2]
- (d)(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 3(d)(ii) in the evidence document.[1]
- (d)(iii)Test your program. Take a screenshot of the output. Save your program. Copy and paste the screenshot into part 3(d)(iii) in the evidence document.[1]
Mark scheme
Marking points from the official mark scheme (Oct/Nov 2023). The mark or mark type is shown in brackets.
- [5] One mark each: • Class declaration • Four attributes with correct data types • Constructor header • ... taking 4 parameters • Setting attributes to parameter values
- [3] One mark each: • 1 get header with no parameter ... • ... returning attribute • Second correct get method
- [2] One mark each • Set header with 1 parameter ... • ... assigns parameter to attribute
- [1] One mark for method multiplying attribute intelligence by 1.1 (or equivalent) and storing in attribute.
- [2] One mark each • Method (function) header (and end where appropriate) no parameter, returning a calculated age • Extracting attribute year of birth from date and subtracting from 2023
- [2] One mark each: • Creating new instance of Character with identifier FirstCharacter • ... sending correct values as parameters
- [3] One mark each • Calling Learn() for FirstCharacter • Calling ReturnAge() and outputting return value • Outputting name and intelligence using gets with suitable message
- [1] One mark for screenshot with Royal, 4 years, 77 intelligence e.g. Royal is 4 years old and has intelligence 77.0
- [5] One mark each: • Class header inheriting from Character • Declaring Element as string • Constructor header taking 5 parameters ... • ... calling parent constructor with the 4 parameters • ... assigning parameter to Element
- [3] One mark each: • Method header overriding parent method but no parameters • Checking element value ... • ... correct calculations with attribute intelligence and storing
- [2] One mark each: • Declaring MagicCharacter with identifier FirstMagic ... • ... with correct parameters
- [1] One mark for calling Learn() for FirstMagic and outputting all required data in appropriate message using gets.
- [1] One mark for screenshot e.g. Light is 5 years old and has intelligence 90.0
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →