A company needs a computer program to store data about its employees. Part of the program is being written using object-oriented programming. The class Employee stores data about the employees. Each employee has an employee number, a job title and hourly pay rate. The class will also store the amount they are paid each week over a 52-week year in a 1D array. Employee HourlyPay : REAL stores the amount each employee gets paid each hour EmployeeNumber : STRING stores the employee's unique number JobTitle : STRING stores the employee's job title PayYear2022 : ARRAY[0:51] OF REAL stores the amount the employee has been paid each week Constructor() initialises HourlyPay, EmployeeNumber and JobTitle from the values passed as parameters initialises all 52 elements in PayYear2022 to 0.0 GetEmployeeNumber() returns the employee number SetPay() takes the week number and number of hours worked that week as parameters calculates and stores the pay for that week in PayYear2022 GetTotalPay() returns the total of all the values in PayYear2022
- (a)(i)Write program code to declare the class Employee. You only need to declare the class and its constructor. Do not declare any other methods. Use your programming language appropriate constructor. If you are writing program code in Python, include attribute declarations using comments.[5]
- (a)(ii)The method GetEmployeeNumber() returns the employee number. Write program code for the method GetEmployeeNumber().[2]
- (a)(iii)The method SetPay(): • takes a week number and the number of hours worked that week as parameters • calculates the pay for that week by multiplying the hourly pay by the number of hours worked that week • stores the calculated pay in the appropriate index for that week in PayYear2022. Write program code for the method SetPay().[3]
- (a)(iv)The method GetTotalPay() returns the total of all the values in PayYear2022. Write program code for the method GetTotalPay().[2]
- (b)(i)The child class Manager inherits from the parent class Employee. A manager gets a bonus. This bonus value is a percentage, for example 10.0%. When calculating the pay, the number of hours the manager worked that week is increased by the bonus value. Manager BonusValue : REAL stores the bonus value, for example 10.0 represents a 10.0% increase Constructor() takes bonus value, hourly pay, employee number and job title as parameters initialises BonusValue to its parameter value SetPay() takes the week number and number of hours worked as parameters increases the number of hours worked by the bonus value calls the SetPay() method from the parent class Write program code to declare the class Manager. You only need to declare the class and its constructor. Do not declare any other methods. Use your programming language appropriate constructor. If you are writing in Python, include attribute declarations using comments.[4]
- (b)(ii)The Manager method SetPay() overrides the method from the parent class and: • takes the week number and number of hours worked as parameters • increases the number of hours worked by the bonus value • calls SetPay () from the parent class. Write program code for the method SetPay().[3]
- (c)The main program has a global 1D array, EmployeeArray, to store data about eight employees. Each employee is stored as an object of type Employee. The file Employees.txt stores data about the employees, in the order: • hourly pay • employee number • bonus value (where included) • job title. Only employees who are managers have a bonus value saved. For example: • The first employee is a Junior Developer, with employee number 12452 and an hourly pay of $15.22. This employee does not have a bonus value. • The third employee is an Interface Manager, with employee number 02586 and an hourly pay of $22.50. This employee has a bonus value of 5.25%. Write the main program to: • declare the array to store data about 8 employees • read in the data from the file for each employee • instantiate each employee as either Employee (if the employee does not have a bonus value) or Manager (if the employee has a bonus value).[7]
- (d)The file HoursWeek1.txt stores the number of hours each employee has worked in week 1, in the order: • employee number • number of hours worked. For example, the first set of data is for employee 21548 who has worked 50.0 hours. The procedure EnterHours(): • reads in the values from the file • finds the location of each employee in EmployeeArray • calls the method SetPay() for each employee. Write program code for EnterHours().[4]
- (e)(i)The main program needs to call EnterHours() and use the method GetTotalPay() to output the employee number and total pay for each of the eight employees. Amend the main program to perform these tasks.[2]
- (e)(ii)Test your program. Take a screenshot of the output.[1]
This question uses a diagram from the original paper, which isn't shown here. Open the full paper from the past papers archive to see it.
Mark scheme
Marking points from the official mark scheme (May/June 2023). The mark or mark type is shown in brackets.
- [1] Class Employee declaration (and end where appropriate)
- [1] All 4 attributes declared with suitable data types, array with (min) 52 elements
- [1] Constructor header within class (and end where appropriate) taking 3 parameters ...
- [1] ...assigning parameters to attributes within constructor
- [1] ...initialising 52 elements of array to 0.0 within constructor
- [1] Get method header (and end) with no parameters ...
- [1] ... returning employee number (without overriding)
- [1] Method header (and close) with two parameters (week number and number of hours)
- [1] Calculates pay as number of hours (parameter) * HourlyPay (attribute)
- [1] stores result in correct index in PayYear2022
- [1] Method header (and close) and returning calculated total (ignore parameters, allow return of any reasonable attempt at calculation)
- [1] Totalling all elements in PayYear2022
- [1] Class Manager header (and end) inheriting from Employee
- [1] Constructor within class (and end) taking 4 parameters...
- [1] ...calling parent class constructor with 3 values from parameters
- [1] Declaring BonusValue (real) and assigning parameter to it within constructor
- [1] Method SetPay header (and end) taking 2 parameters
- [1] Calculating hours (from parameter) * bonus as a percentage
- [1] Overriding / calling parent SetPay with week number from parameter and updated hours as parameters
- [1] Opening file Employees.txt to read and closing file in an appropriate place
- [1] Exception handling with appropriate output for opening the file
- [1] Looping to EOF / 8 times
- [1] (Attempting to) Read in all lines from the file for each employee
- [1] Instantiating and storing an object of type Manager (not Employee) when bonus is included...
- [1] ...with correct read in values
- [1] (otherwise) instantiating and storing an object of type Employee ...with correct read in values
- [1] Procedure header EnterHours() and opening/closing file (with exception handling)
- [1] Looping to EOF/8 times and reading in employee number and hours worked per line
- [1] Searching array for the matching employee number using GetEmployeeNumber()
- [1] Calling SetPay() for the identified employee with week number 1 and the hours worked
- [1] Calling EnterHours() and looping through each employee
- [1] outputting the employee number and their total pay using GetTotalPay() and GetEmployeeNumber()
- [1] 1 mark for screenshot e.g. (list of employee numbers and total pay matching example)
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →