Skip to main content
A-LevelComputer ScienceFurther programming9618/42 · May/June 2022 · Q327 Marks

A programmer is designing a computer game that uses a set of cards. Each card has a number and a colour. The cards are saved in the text file CardValues.txt The program has a class named Card. The class has the following attributes and methods. Card Number : INTEGER The number of the card Colour : STRING The colour of the card Constructor() Takes two values as parameters and sets them to the private attributes GetNumber() Returns the number of the card GetColour() Returns the colour of the card

  1. (a)The constructor takes the number and colour of the card as parameters and sets them to the private attributes. Write program code to declare the class Card and its constructor. Do not write any other methods. Use your programming language appropriate constructor. All attributes should be private. If you are writing in Python, include attribute declarations using comments.[5]
  2. (b)The two get methods return the associated attribute. Write program code for the get methods GetNumber() and GetColour().[3]
  3. (c)The text file CardValues.txt stores the data for 30 cards, in the order: number, colour. For example, the first card in the text file: 1 is the number red is the colour. A 1D array of type Card is declared to store all the cards read in from CardValues.txt Write the main program to: • declare an array of type Card with 30 elements • read in the data for the 30 cards from CardValues.txt and assign each to the array.[7]
  4. (d)The program needs to allow all players (maximum of 5) to select 4 cards from the 30 available. A card can only be selected once, so the program needs to record which cards have already been selected. The function, ChooseCard(): • takes as input an integer to represent an array index from 1 to 30 • validates that the value is between 1 and 30 inclusive • checks if the card is available (it has not already been selected) • loops until an available card is selected • returns the index of the card if it is available. Amend the program to store which cards have already been selected and write program code for the function ChooseCard().[6]
  5. (e)(i)The main program needs to allow one player to select all their 4 cards. Amend the main program to: • create an array, Player1, for player 1 of type Card • ask player 1 to input 4 integers using the function from part 3(d) • store the cards in Player1 • output the number and colour of the 4 cards in Player1.[5]
  6. (e)(ii)Test your program with the following test data: Test 1: 1 5 9 10 Test 2: 2 2 3 4 4 5 Take a screenshot to show the output.[1]

Mark scheme

Marking points from the official mark scheme (May/June 2022). The mark or mark type is shown in brackets.

  1. [5] 1 mark per mark point • Card class declaration (and end where appropriate) • Both attributes (Number and Colour) declared with suitable data types ... • ...as private • correct constructor header (and end where appropriate) with two parameters ... • ...both parameters assigned to the attributes
  2. [3] 1 mark per mark point • 1 get method header (and close where appropriate) with no parameter ... • ... returning attribute • 2nd correct get method
  3. [7] 1 mark per mark point to max 7 • Declaration of array with 30 elements of type Card • Opening the text file CardValues.txt for read • Looping until EOF/30 times • Reading in all sets of 2 lines (number then colour) ... • ...creating object of type Card... • .with number and colour read in from file ... • ...storing in next array element • Try and catch for file handling...s • ....with appropriate outputs • Closing the file in a suitable place
  4. [6] 1 mark per mark point to max 6 • Implementing a suitable way of storing which card have been selected • Function ChooseCard() header (and close) and returning an integer (index) in all cases • Reading in array index from the user ... • ...with suitable validation looping until it is between 1 and 30 (inclusive) • Converting input to array index (e.g. -1 each time) • Check if the input is already selected... • ... if it is selected, loop until index input is not already selected • ... returning index of available card selected • Stores the valid Card chosen as taken (using any suitable method)
  5. [5] 1 mark per mark point • declaring array Player1 of type Card • calling the function ChooseCard() four times • storing the card, that is in the index returned, in the array Player1 • outputting all four numbers and colours in Player1 ... • ... using the get methodss
  6. [1] 1 mark for both tests Test 1: inputting 1, 5, 9, 10. Outputting: 1 red 9 green 9 orange 10 red Test 2: inputting 2 2 3 4 4 5. Outputting: 2 already taken. Then 5 black 2 while 4 red 9 green Test 1 e.g.

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 →

About this question

Topic
Further programming, A-Level Computer Science (syllabus 9618). Structured question, 27 marks.
Source
A-Level Computer Science, May/June 2022 Paper 4 Variant 2, question 3.

Questions and mark schemes are from past examination papers and remain the copyright of the exam board. How Oracle Prep builds its content

Related Computer Science questions

© 2026 Oracle Prep