A computer program is being developed that uses a set of cards. The program is written using object-oriented programming. The program has two classes: Card and Hand. The methods and attributes of these classes are shown: Card Number: INTEGER stores the card number from 1 to 5 inclusive Colour : STRING stores the card colour: red, blue or yellow Constructor() takes a number and colour as parameters and sets the private values to these parameters GetNumber() returns the card number GetColour() returns the card colour Hand Cards : ARRAY[0:9] OF Card 1D array of type Card FirstCard : INTEGER stores the position of the first card in the hand NumberCards : INTEGER stores the number of cards in the hand Constructor() takes five card objects as parameters, assigns each card to the array Cards[], initialises FirstCard to 0 and NumberCards to 5 GetCard() takes an index as a parameter and returns the card at that index in the array
- (a)(i)Write program code to declare the class Card, its attributes and constructor. Do not write program code for the get methods. Use your programming language appropriate constructor. All attributes must be private. If you are writing in Python, include attribute declarations using comments.[5]
- (a)(ii)Write program code for the class methods GetNumber() and GetColour().[3]
- (a)(iii)The program is tested with the following cards: Number | Colour ---|--- 1 | red 2 | red 3 | red 4 | red 5 | red 1 | blue 2 | blue 3 | blue 4 | blue 5 | blue 1 | yellow 2 | yellow 3 | yellow 4 | yellow 5 | yellow Write program code to declare each of these cards as a variable of type Card in the main program.[2]
- (b)(i)Write program code to declare the class Hand, its attributes and constructor. Do not write the get methods. Use your programming language appropriate constructor. All attributes must be private. If you are writing in Python, include attribute declarations using comments.[6]
- (b)(ii)The get method GetCard() takes an index as a parameter and returns the card stored at that index in the array. Write program code for the method GetCard().[2]
- (b)(iii)Two players are declared with 5 cards each. Player 1 has the cards: 1 red, 2 red, 3 red, 4 red, 1 yellow. Player 2 has the cards: 2 yellow, 3 yellow, 4 yellow, 5 yellow, 1 blue. Write program code to declare player 1 and player 2 as objects of type Hand, with the cards indicated.[2]
- (c)(i)The function CalculateValue() takes a player's hand as a parameter and returns a score calculated using the following rules: • If a card is red, 5 points are added to the player's score. • If a card is blue, 10 points are added to the player's score. • If a card is yellow, 15 points are added to the player's score. • The number of each card in the hand is added to the player's score. Write program code for the function CalculateValue(). Assume that there are only 5 cards in the player's hand in this function.[6]
- (c)(ii)Amend the main program by writing program code to use the function CalculateValue() for each of the two players. The player with the highest score wins. Output an appropriate message to identify the winning player, or if the game was a draw (both players have the same number of points).[4]
- (c)(iii)Test your program. Take a screenshot to show the output. Copy and paste the screenshot into part 2(c)(iii) in the evidence document.[1]
Mark scheme
Marking points from the official mark scheme (Oct/Nov 2022). The mark or mark type is shown in brackets.
- 1 mark per point:
- [1] class Card declaration (and end where appropriate)
- [1] Private attributes declared Number as integer and Colour as string
- [1] constructor header (and end where appropriate)...
- [1] ...taking 2 parameters
- [1] assigning parameters to attributes
- 1 mark per point:
- [1] 1 get method as function (and end where appropriate) with no parameters...
- [1] ...returning the value
- [1] 2nd correct get method
- 1 mark per point:
- [1] one card initialised as type Card
- [1] all 15 cards initialised correctly as type Card
- 1 mark per point:
- [1] class Hand declaration (and end where appropriate)
- [1] private attribute declarations; FirstCard as integer, NumberCards as integer
- [1] private attribute array named Cards of type Card with 10 elements
- [1] constructor with 5 Card objects as parameters
- [1] assigning each Card parameter to the array (in constructor)
- [1] initialising FirstCard to 0 and NumberCards to 5 (in constructor)
- 1 mark per point:
- [1] function GetCard() header (and end where appropriate) taking (integer) parameter
- [1] returning the card at parameter index in array
- 1 mark per point:
- [1] 2 variables (player 1 and player 2) of type Hand
- [1] using constructor and sending the correct variables as parameters
- 1 mark per point:
- [1] function CalculateValue() header (and end where appropriate) taking one parameter and initialising score to 0
- [1] looping through all 5 Card objects in parameter array...
- [1] adding 5 to score for red, 10 to score for blue, 15 to score if yellow
- [1] adding each card number to score
- [1] Using GetCard(),GetColour() and GetNumber() correctly
- [1] Returning calculated score
- 1 mark per point:
- [1] One function call of CalculateValue()for each player
- [1] ...sending the player's hand as parameter
- [1] Comparing return values and outputting the player with the highest score in an appropriate message
- [1] ... or if there was a draw in appropriate message
- [1] Output showing player 2 wins, for example:
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 →