Question 6

OCR Computer Science June 2017 Paper 2A level40 marks

On the specification

(a)
2.1 Elements of computational thinking
(b)(i)
2.1 Elements of computational thinking
(b)(ii)
2.1 Elements of computational thinking
(c)(i)
2.2 Problem solving and programming
(c)(ii)
2.2 Problem solving and programming
(d)(i)
2.2 Problem solving and programming1.2 Software and software development
Question text

6 A software developer is creating a Virtual Pet game. The user can choose the type of animal they would like as their pet, give it a name and then they are responsible for caring for that animal. The user will need to feed, play with, and educate their pet. The aim is to keep the animal alive and happy, for example if the animal is not fed over a set period of time then the pet will die. • The game tells the user how hungry or bored the animal is as a percentage (%) and the animal’s intelligence is ranked as a number between 0 and 150 (inclusive). • Hunger and boredom increase by 1% with every tick of a timer. • When the feed option is selected, hunger is reduced to 0. • When the play option is selected, bored is reduced to 0. • When the read option is selected, the intelligence is increased by 0.6% of its current value. An example of the game is shown: What type of pet would you like? Fox or Elephant? Fox What would you like to name your Fox? Joanne Joanne’s stats are Hunger: 56% Bored: 85% Intelligence: 20 What would you like to do with your pet? Play, Read or Feed? Fig. 1.1 (a) Identify three inputs that the user will have to enter to start, and/or play the game. 1 2 3 [3] (b) The developer is using decomposition to design the game. (i) Describe the process of decomposition. [2] (ii) The developer has produced the following structure diagram for the game: Virtual Pet Start game Play game Choose Pet Feed Read Timer Reduce Hunger to 0 Complete the structure diagram for the Virtual Pet game by filling in the empty boxes. [6] (c) The developer needs to write procedures for the options play and read. Each of the options changes its corresponding value, and outputs the results to the screen. (i) Write a procedure, using pseudocode, to reset bored and output the new value in an appropriate message. [3] (ii) Write a procedure, using pseudocode, to increase intelligence by 0.6% and output the new intelligence in an appropriate message. [3] (d) The developer is extending the game to allow users to have multiple pets of different types. The developer has written a class, Pet. The attributes and methods in the class are described in the table: Identifier Attribute/Method Description petName Attribute Stores the pet’s name bored Attribute Stores the % bored hunger Attribute Stores the % hunger intelligence Attribute Stores the intelligence type Attribute Stores the type of animal new Method Creates a new instance of pet feed Method Reduces hunger to 0 and outputs hunger play Method Reduces bored to 0 and outputs bored read Method Increases intelligence by a set value outputGreeting Method Outputs a message to the user Part of the class declaration is given: class Pet private petName private bored private hunger private intelligence private type (i) After a user enters the pet name, and chooses a type, the constructor method of Pet is called to create a new instance. The method needs to set petName, as well as hunger, bored and intelligence to starting values of 0. Write, using pseudocode, the constructor method for this class. [4] (ii) Write a line of code that creates a new instance of Pet for a Tiger called “Springy”. [2] (iii) The method outputGreeting for the superclass is written as follows: public procedure outputGreeting() print("Hello, I'm " + petName + ", I'm a " + type) endprocedure A class is needed for Tiger. The class needs to: • inherit the methods and attributes from pet • in the constructor, set type to Tiger, intelligence to 10, hunger to 50 and bored to 10 • extend the method outputGreeting, by outputting an additional line that says “I like to eat meat and roar” Write, using pseudocode, the class Tiger. [5] (e*) The developer made use of abstraction when creating the Virtual Pet game. Discuss the need for and purpose of abstraction and how abstraction will be used in the development of the game. [9] (f) The developer is storing the user’s pets in a 1-dimensional array. At each timer interval, the array is searched, using a linear search, to check if any pets’ hunger or bored values are greater than 90%. If they are, an alert is displayed to the user. (i) State the complexity of searching the pets in Big-O notation. [1] (ii) A given computer takes 4 milliseconds (ms) to search an array of 20 pets. Calculate an estimate of how long the computer will take to search an array of 100 pets. Show your working. [2]