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. [Figure X.X] 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 10000 inclusive SetYPosition() adds the parameter to the Y position validates that the new Y position is between 0 and 10000 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]
- (a)(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]
- (a)(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 10000, it is limited to 10000. 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]
- (a)(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. Direction Value change up Y position + 10 down Y position – 10 left X position – 10 right X position + 10 Use the appropriate method to change the position value. 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)(i)The class BikeCharacter inherits from the class Character. [Figure X.X] 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 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]
- (c)(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 program code into part 3(d) in the evidence document.[1]
- (e)(i)Write program code to: • take as input which of the two characters the user would like to move • take as input the direction the user would like the character to move • call the appropriate method to move the character • output the character's new X and Y position in an appropriate format, for example: "Karla's new position is X = 100 Y = 200" All inputs require appropriate prompts and must be validated. Save your program. Copy and paste the program code into part 3(e)(i) in the evidence document.[5]
- (e)(ii)Test your program twice with the following inputs. Test 1: jack right Test 2: karla down Take a screenshot of the output. Save your program. Copy and paste the screenshot into part 3(e)(ii) in the evidence document.[2]
This question uses a diagram from the original paper, which isn't shown here. Open the full paper from the past papers archive to see it.
Mark scheme
Marking points from the official mark scheme (Oct/Nov 2023). The mark or mark type is shown in brackets.
- [4] One mark each to max 4
- • Class header (and end where appropriate)
- • Three attributes with correct names and data types
- • Constructor header (and end where appropriate) with 3 parameters
- • Within constructor, assigns attributes to parameters
- [3] One mark each
- • 1 get header with no parameter ...
- • ... returning correct value
- • 2nd get method
- [4] One mark each to max 4
- • 1 set method header (and end where appropriate) with parameter
- • adding parameter to X/Y Position attribute and storing in the X/Y attribute
- • If (resulting value is) more than 10 000 limiting to 10 000 and if less than 0 limiting to 0
- • Second correct set method
- [4] One mark each
- • Method header with (string) parameter
- • Checking parameter for direction ...
- • ... using SetYPosition() and SetXPosition() correctly ...
- • ... with correct parameters
- [2] One mark each
- • New instance of Character created with identifier Jack ...
- • ... correct constructor called and values passed
- [3] One mark each
- • Class header inheriting from Character
- • Constructor taking all 3 parameters ...
- • ... calling parent/super constructor with the 3 parameters
- [2] One mark each
- • Method header taking parameter and overriding parent/super Move ()
- • Correct changes to method to update values by 20
- [1] One mark each
- • Declaring new BikeCharacter with correct values e.g.
- [5] One mark each to max 5
- • Reading in both values (character and direction) with appropriate prompts
- • Character name is validated as e.g. Jack/Karla, and direction is validated as e.g. up/down/left/right
- • Calling Move () for the character input, with direction input as a parameter
- • Outputting character's new X and Y position in a suitable format ...
- • ... using get methods
- [2] One mark for each test
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 →