Employee Hourlypaidemployee Salariedemployee: 9608/42/M/J/15 © Ucles 2015
Employee Hourlypaidemployee Salariedemployee: 9608/42/M/J/15 © Ucles 2015
[3]
• methods
• SetEmployeeName
• SetEmployeeID
• CalculatePay
Write program code for the class definition of the superclass Employee.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [5]
© UCLES 2015 9608/42/M/J/15
9
(c) (i) State the properties and/or methods required for the subclass HourlyPaidEmployee.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [4]
(ii) State the properties and/or methods required for the subclass SalariedEmployee.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [2]
(d) Name the feature of object-oriented program design that allows the method CalculatePay
to be declared in the superclass Employee.
...................................................................................................................................................
.............................................................................................................................................. [1]
A program will store and process data about the teams in the competition.
The program can output the full name and date of birth of any member. For example, “Nadia Abad
16/05/1995”
An introduction about a team member can be output using their name. For example, “Hello, I’m
Nadia Abad”.
The program outputs a different version of the introduction for a competitor. This version includes
the competitor’s sport. For example, “Hello, I’m Sally Jones and my sport is Skateboard Park.”
(a) Complete the following class diagram to show the attributes, methods and inheritance for the
program.
Member Team
FirstName : STRING TeamName : STRING
DateOfBirth : DATE
Gender : STRING
Constructor() Constructor()
Introduction() ......................................................................
DisplayFullnameAndDateOfBirth() ......................................................................
Competitor Official
Sport : STRING
..........................................................................
..........................................................................
Constructor() Constructor()
Introduction() DisplayJobTitle()
[3]
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[5]
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[5]
(d) Omar Ellaboudy is an official at X-Games. He is first-aid trained and his job title is Judge. He
is male and was born on 17/03/1993.
Write program code to create an instance of an object with the identifier BMXJudge. All
attributes of the instance must be fully initialised.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[3]
(b) The company wants to implement a program for the marking system. It will do this with
object-oriented programming (OOP).
Many candidates take the examination. Each examination paper is given a PaperID that is
made up of the centre (school) number followed by the candidate number.
The following diagram shows the design for the ExaminationPaper class. This includes
the attributes and methods.
ExaminationPaper
FinalMark : INTEGER // maximum 2 digits, initialised to 0
Grade : STRING // "Pass", "Merit", "Distinction"
// or "Fail", initialised to "Fail"
PaperID : STRING // centre number followed by the
// candidate number, for example
// "ZZ00991001"
Create() // creates and initialises a new instance
// of the ExaminationPaper class using
// language-appropriate constructor
SetFinalMark() // checks that the mark parameter has a
// valid value, if so, assigns it to
// FinalMark
SetGrade() // sets Grade based on FinalMark
GetFinalMark() // returns FinalMark
GetGrade() // returns Grade
GetPaperID() // returns PaperID
(i) The constructor receives the centre number and candidate number as parameter values
to create PaperID. Other properties are initialised as instructed in the class diagram.
Program code
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [5]
(ii) Get and set methods are used to support the security and integrity of data in
object-oriented programming.
Explain how get and set methods are used to support security and integrity.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [3]
(iii) Write program code for the following three get methods.
GetFinalMark()
Program code
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
GetGrade()
Program code
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
GetPaperID()
Program code
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[4]
(iv) The method SetFinalMark() checks that its INTEGER parameter Mark is valid. It is
then set as the final mark if it is valid. A valid mark is greater than or equal to 0 and less
than or equal to 90.
If the mark is valid, the method sets the final mark and returns TRUE.
If the mark is not valid, the method does not set the final mark and returns FALSE.
Program code
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [5]
Grade Criteria
Distinction >= DistMark
Merit >= MeritMark
Pass >= PassMark
Fail < PassMark
Program code
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [4]
(vi) Emily is a candidate who has taken the examination paper. The grades are awarded as
follows:
Grade Criteria
Distinction >= 80
Merit >= 70
Pass >= 55
• allows the centre number, candidate number and mark to be input, with suitable
prompts
• assigns an instance of ExaminationPaper to the variable ThisPaper
• sets the mark for the object
• sets the grade for the object
• outputs the grade for the object
Program code
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [8]
© UCLES 2019 9608/42/M/J/19 [Turn over
10
(c) The examination paper will be taken by many candidates in centres around the world.
The program stores the objects of the ExaminationPaper class in a file. The company has
decided to use a hash table, rather than a linked list to store the objects.
Explain why a hash table is more suitable than a linked list to store the objects.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
7 A programmer is creating a computer game. The programmer has designed the class, Character,
for the characters in the game.
The following class diagram shows the design for the Character class.
Character
Name : STRING // initialised in constructor to the parameter
value passed to the constructor
Skill : INTEGER // initialised in constructor to 0
Health : INTEGER // initialised in constructor to 50
Shield : INTEGER // initialised in constructor to a random value
between 1 and 25 (inclusive)
Constructor() // method used to create and initialise an object
GetName() // returns Name value
GetSkill() // returns Skill value
GetHealth() // returns Health value
GetShield() // returns Shield value
SetSkill() // increases Skill by the parameter value
SetHealth() // increases or decreases Health by the parameter
value
SetShield() // increases or decreases Shield value by the
parameter value
(a) Write program code for the Constructor() method. Use the appropriate constructor
method for your chosen programming language.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(c) The method SetSkill() validates the parameter value and updates the value of Skill.
The method is passed an INTEGER parameter that must be between 10 and 25 (inclusive). A
value outside of this is not valid.
If the parameter value is valid, the method will increase Skill by the parameter value. The
maximum value that Skill can be increased to is 200. For example:
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
(d) There are five characters in the game. All the character objects are stored in a 1D array.
Write pseudocode to declare the array, CharacterArray, to store the five character
objects.
...................................................................................................................................................
............................................................................................................................................. [2]
(e) The game has the character with the name Victory.
Write program code to create the character Victory as an instance of the class Character.
The object needs to be stored in the first element of the array CharacterArray.
Program code
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
Tick (3) one box in each row to show whether the statement applies to Serial, Sequential or
Random format.
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of
Cambridge Local Examinations Syndicate (UCLES), which itself is a department of the University of Cambridge.
3 Ejaz is creating a program that will allow the user to create quizzes. He is using object-oriented
programming (OOP).
The class attributes and methods are in the following tables. All attributes are declared as private.
QuestionClass
QuizClass
(a) Write program code to define the class QuizClass. You are only required to write code for
the attribute declarations and constructor.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
(b) The QuizClass method AddQuestion() takes a question object as a parameter and stores
it in the next available location in the array Questions. It returns TRUE if it is successfully
stored, and FALSE otherwise.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
...................................................................................................................................................
............................................................................................................................................. [1]
(e) Ejaz can use an interpreter and a compiler to translate program code during the development
process. The program will be distributed without any access to the source code.
(i) State when Ejaz should use an interpreter and a compiler. Each answer must be different.
Interpreter ..........................................................................................................................
...........................................................................................................................................
Compiler ............................................................................................................................
...........................................................................................................................................
[2]
(ii) Give the name of two facilities that Ejaz can use to debug his program.
1 ........................................................................................................................................
...........................................................................................................................................
2 ........................................................................................................................................
...........................................................................................................................................
[2]
(iii) Describe one feature of an editor that Ejaz can use when writing the program.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
A part-time student attends one or more courses. A fee is charged for each course. The number of
courses a part-time student attends is recorded, along with the total fee and whether or not the fee
has been paid.
The college needs a program to process data about its students. The program will use an object-
oriented programming language.
(a) Complete the class diagram showing the appropriate properties and methods.
Student
StudentName: STRING
........................................................................
........................................................................
........................................................................
ShowStudentName()
........................................................................
........................................................................
........................................................................
FullTimeStudent PartTimeStudent
Address: STRING
.......................................................................
.......................................................................
.......................................................................
.......................................................................
.......................................................................
.......................................................................
.......................................................................
Constructor()
.......................................................................
ShowAddress()
.......................................................................
.......................................................................
.......................................................................
.......................................................................
.......................................................................
[7]
© UCLES 2015 9608/42/O/N/15
7
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [2]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [3]
• identifier: NewStudent
• name: A. Nyone
• date of birth: 12/11/1990
• telephone number: 099111
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [3]
The dictionary ADT is to be implemented as a two-dimensional array. This stores key-value pairs.
The CreateDictionary operation initialises all elements of Dictionary to the empty string.
(a) The hashing function Hash is to extract the first letter of the key and return the position of this
letter in the alphabet. For example Hash("Action") will return the integer value 1.
(Note: The ASCII code for the letter A is 65.)
Number ← ...........................................................................................................................
............................................................................................................................................
ENDFUNCTION
[5]
(b) A company wants to simulate the use of a ticket machine. It will do this with object-oriented
programming (OOP).
The following diagram shows the design for the class TicketMachine. This includes its
attributes and methods.
TicketMachine
Amount : INTEGER // total value of coins inserted in cents
State : STRING // "Idle", "Counting", "Cancelled"
// or "Accepted"
Create() // method to create and initialise an object
// if using Python use __init__
SetState() // set state to parameter value
// and output new state
StateChange() // insert coin or press button,
// then take appropriate action
CoinInserted() // parameter is a string
// change parameter to integer
// and add coin value to Amount
ReturnCoins() // output Amount, then set Amount to zero
PrintTicket() // print ticket, then set Amount to zero
(i) Create()
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[3]
(ii) SetState()
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
(iii) ReturnCoins()
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [2]
(iv) Each coin inserted must be one of the following: 10, 20, 50 or 100 cents.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[3]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
(vi) Convert the flowchart to program code for the method StateChange().
Use the attributes and methods in the original class definition and the ValidCoin()
function from part (iv).
METHOD StateChange
INPUT NewInput
No
CALL ReturnCoins()
No
No No
Is NewInput Yes
CALL CoinInserted(NewInput)
a valid
coin?
No
CALL SetState("Counting") CALL SetState("Idle")
OUTPUT "Error –
not a valid
coin"
ENDMETHOD
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.....................................................................................................................................[12]
© UCLES 2016 9608/42/O/N/16 [Turn over
8
(vii) The company needs to write a program to simulate a parking meter. The program
will create an object with identifier ParkingMeter, which is an instance of the class
TicketMachine.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[4]
TicketMachine
PRIVATE
Amount : INTEGER
State : STRING
PUBLIC
Create()
StateChange()
PRIVATE
SetState()
CoinInserted()
ReturnCoins()
PrintTicket()
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
(ii) Describe the effects of declaring two methods of the class as public and the other four as
private.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
6 A bank has a range of customer accounts, which includes current accounts and savings accounts.
• an account number
• a balance (amount of money in an account).
A current account has a level (bronze, silver or gold). A monthly fee ($) is taken from each account.
Savings account customers pay a regular amount ($) into their account. The payment interval is a
number of weeks (for example, 4).
Account
AccountNumber : STRING
Balance : CURRENCY
Constructor()
GetAccountNumber()
GetBalance()
SetAccountNumber()
SetBalance()
CurrentAccount SavingsAccount
.................................................................... .....................................................................
.................................................................... .....................................................................
.................................................................... .....................................................................
.................................................................... .....................................................................
Constructor()
.....................................................................
....................................................................
.....................................................................
....................................................................
.....................................................................
....................................................................
.....................................................................
....................................................................
GetPaymentInterval()
SetPaymentInterval()
[3]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[5]
© UCLES 2017 9608/42/O/N/17 [Turn over
14
(c) Write program code to declare the SavingsAccount class. Do not write any get or set
methods.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[5]
© UCLES 2017 9608/42/O/N/17
8
4 A circus is made up of performers. There are three types of performer: clown, acrobat and aerial.
• First name
• Last name
• Secondary role (that can be edited)
• Stage name (that can be edited)
• Type of performer (PerfType)
Each of the three types of performer has a method that will display all of the information about that
performer in a specific format. For example:
Sally Superstar (real name Sally Smith) is an acrobat. Fire is part of Sally Superstar’s act.
When not performing, Sally Superstar is a set changer.
(a) Complete the following class diagram to show the attributes, methods and inheritance for
the program.
Performer Acrobat
FirstName : STRING UseFire : BOOLEAN
LastName : STRING
SecondaryRole : STRING
Constructor()
StageName : STRING
PerformerInfo()
PerfType : STRING
Constructor()
EditSecondaryRole()
EditStageName()
Clown Aerial
............................................................. .............................................................
.............................................................
Constructor() Constructor()
............................................................. .............................................................
[4]
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [5]
Sally Superstar (real name Sally Smith) is an acrobat. Fire is part of Sally Superstar’s act.
When not performing, Sally Superstar is a set changer.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [8]
Amazing Alex (real name Alex Tan) is an acrobat. Fire is part of Alex’s act. When not
performing, Amazing Alex is a popcorn seller.
(i) Write program code to create an instance of an object with the identifier Acrobat_1.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [3]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [2]
(c) The company decides to implement a program for the software using object-oriented
programming (OOP).
Each employee has a unique employee ID, name, address and date of birth. There are two
types of employee: salary and apprenticeship.
Salaried employees are paid a fixed monthly payment. The hours a salary employee works in
a month are recorded to calculate bonus payments. They may receive bonus payments and
make pension payments (given in part(b)).
Apprenticeship employees are paid weekly. They receive an hourly rate of pay. Apprenticeship
employees do not receive bonus payments or make pension payments.
Employee
EmployeeID : STRING
Name : STRING
Address : STRING
DateOfBirth : Date
Constructor()
GetEmployeeID()
GetName()
GetAddress()
GetDateOfBirth()
SetEmployeeID()
SetName()
SetAddress()
SetDateOfBirth()
SalaryEmployee ApprenticeshipEmployee
MonthlyPayment : CURRENCY
HoursThisMonth: REAL ........................................................
PublicHoliday : BOOLEAN
........................................................
Pension : BOOLEAN
Constructor()
GetMonthlyPayment() ........................................................
GetHoursThisMonth()
........................................................
GetPublicHoliday()
GetHourlyRate()
GetPension()
GetHoursThisWeek()
SetMonthlyPayment()
SetHourlyRate()
SetHoursThisMonth()
SetPublicHoliday()
SetPension()
[3]
© UCLES 2019 9608/42/O/N/19
5
(ii) Write program code for the Constructor() in the Employee class.
Program code
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [4]
(iii) Write program code for the GetEmployeeID()method in the Employee class.
Program code
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(iv) Write program code for the SetEmployeeID()method in the Employee class.
Program code
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
Program code
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [4]
4 A programmer wants to create a mobile application to record the number of calories a person eats
in a day.
The programmer has designed the class, FoodItem, to store details for each item of food.
The following diagram shows the design for the FoodItem class.
FoodItem
FoodID : STRING // initialised in constructor to parameter value
Name : STRING // initialised in constructor to an empty string
Calories : INTEGER // initialised in constructor to 0
Constructor() // method used to create an instance of the
// FoodItem class and initialise its attributes
GetFoodID() // returns FoodID
GetName() // returns Name
GetCalories() // returns Calories
SetFoodID() // sets the FoodID to the parameter value
SetName() // sets the Name to the parameter value
SetCalories() // validates the parameter value to make sure
// it is a positive integer less than 2000, and
// then sets Calories to this value
Use the appropriate constructor method for your chosen programming language.
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(c) The method SetCalories() validates the integer parameter value that is passed to it. It
checks that the value is positive and is less than 2000.
The method sets Calories to the parameter value and returns TRUE if the parameter value
is valid. It returns FALSE if the parameter value is not valid.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
CustomerProfile FoodItem
Name : STRING FoodID : STRING
Email : STRING Name : STRING
TotalCalories : INTEGER Calories : INTEGER
GetName() GetFoodID()
GetEmail() GetName()
GetTotalCalories() GetCalories()
SetName() SetFoodID()
SetEmail() SetName()
SetTotalCalories() SetCalories()
DailyCalories
Date : DATE
TotalCalories : INTEGER
GetDate()
SetDate()
GetTotalCalories()
SetTotalCalories()
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(ii) Explain what is meant by inheritance, using an example from the class diagram.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(iii) Explain what is meant by polymorphism, using an example from the class diagram.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(i) Independent modules are combined to create the final program. Testing is performed to
make sure they interact correctly.
..................................................................................................................................... [1]
(ii) Testing is performed to prove to the customer that the system works correctly and meets
the requirements specified in the design.
..................................................................................................................................... [1]
(iii) Test plans are used when testing data. One item that would be included in a test plan is
example test data.
1 ........................................................................................................................................
2 ........................................................................................................................................
[2]
The box has a code that needs to be entered to allow the user into the box. The box contains up
to 10 objects that are defined as being of the class FieldObject. The definition for the class Box
is:
Box
Size : STRING // small, medium or large
Contents : ARRAY[0 : 9] OF FieldObject // the 10 items the box holds
Lock : STRING // the code to unlock the box
Strength : INTEGER // the strength of the box
// decreases by 1 each time an
// incorrect code is entered
Constructor() // instantiates an object of the Box
// class and assigns initial values
// to the attributes
Unlock() // checks if the code is correct to
// unlock the box
GetContents() // returns the array
SetSize() // sets the size of the box
SetContents() // sets the contents of the box
SetLock() // sets the lock code
SetStrength() // sets the strength
(a) The constructor creates a new instance of a box. It takes the size of the box, one item of
content and the lock code as parameters. The strength is initialised to 100.
Write program code to create the class and constructor for Box.
Do not write the code for Unlock() or any of the set or get methods. Use the constructor for
your chosen language.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
(b) The player inputs the code to unlock the box. Each time they enter an incorrect code, the
strength of the box decreases by 1. If the strength of the box becomes 0, the box automatically
unlocks.
• takes the code entered as a parameter and checks if it matches the code to unlock the
box
• returns TRUE if the parameter matches the unlock code
• subtracts 1 from Strength if the parameter does not match the unlock code
• checks if the new value of Strength is less than 1
• returns TRUE if the new value of Strength is less than 1, otherwise it returns FALSE.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
(c) The text file, Progress.txt, stores data about the player’s previous progress.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]