Area 02 · Object-oriented programming
Department payroll
Pay regular and contractual staff of one department through a common base class, record a payslip for each, and show who supervises whom.
- Spec no.
- HO-04
- Level
- Exam-level
- Time box
- 2 h
- Reference
- Java · C#
- Grading
- Self-assessed · rubric is ours, not DICT's
01 Coverage
| Area | Sub-skills practised | Role |
|---|---|---|
| 01 Data manipulation | Validation | Also |
| 02 Object-oriented programming | Abstraction, Encapsulation, Polymorphism, Inheritance, Association, Aggregation, Composition | Primary |
Sign up to start coding practice
Read the task freely. An account is required before editing and running a solution. Code runs also need an internet connection.
Sign up or sign in02 Requirements
- Abstract Employee with private id and name, abstract kind() and gross(), and deduction() that returns 0 by default.
- Regular(id, name, monthly): gross is the monthly salary; deduction is 5% as a practice contribution (not an actual government table).
- Contractual(id, name, dailyRate, days): gross is rate × days; days must be 0 to 31.
- Composition: each employee owns a list of Payslip(gross, net) objects it creates in issuePayslip(). Expose it read-only.
- Association: an employee may have a supervisor, another Employee given by id in the input. Both exist independently.
- Aggregation: a Department holds employees by id but does not create them. Reject duplicate ids.
- Input lines: R id name monthly [supervisorId] or C id name rate days [supervisorId], until end. On any problem print Skipped: <line>.
- Print one line per employee in input order and the department total of net pay.
03 Input and output
- R id name monthly [supId]
- C id name rate days [supId]
- end
- Skipped: lines as they are read
- id name kind gross x net y [supervisor Name]
- Department total net: x.xx
R 1001 Santos 30000
C 2001 Lim 800 22
R 1002 Garcia 25000 1001
C 2002 Uy 800 40
R 1001 Duplicate 1000
endSkipped: C 2002 Uy 800 40
Skipped: R 1001 Duplicate 1000
1001 Santos Regular gross 30000.00 net 28500.00
2001 Lim Contractual gross 17600.00 net 17600.00
1002 Garcia Regular gross 25000.00 net 23750.00 supervisor Santos
Department total net: 69850.00Match the sample exactly first, then write at least two test inputs of your own.
04 Edge cases to test
- Days above 31
- A duplicate id
- A supervisor id that does not exist yet
- A negative salary
05 Starter outline and hints
Payslip(gross, net) — created only inside Employeeabstract Employee { private id, name, supervisor, payslips; issuePayslip() }Regular, Contractual extend EmployeeDepartment { map id → Employee; add rejects duplicates }parse lines → add; then for each: issuePayslip, print, total
Hint 1
Composition: the part's lifetime is tied to the whole. Aggregation: the whole only refers to parts that live elsewhere.
Hint 2
A LinkedHashMap / Dictionary plus an insertion-ordered list keeps input order and fast lookup.
06 Practice rubric
| Criterion | Sub-skills | Look for | Pts |
|---|---|---|---|
| Abstraction and inheritance | AbstractionInheritance | Abstract base; subclasses supply only their pay rule. | 20 |
| Polymorphism | Polymorphism | No type checks in the payroll loop. | 15 |
| Encapsulation | Encapsulation | Private fields, validated constructors, read-only payslip list. | 15 |
| Relationships | AssociationAggregationComposition | Payslips composed, supervisor associated, department aggregating; you can explain the difference. | 30 |
| Correct pay and validation | Validation | Totals match the sample; bad lines skipped. | 20 |
| Total | 100 | ||
Our own weighting for practice. It is not the DICT scoring scheme.
07 Self-check
Tick only what you have verified by running your own program.
Loading saved checks…
08 Reference solution
Both versions compiled and reproduced the sample output on Java 21 and .NET 8 when this site was built. Reference solutions are in Java and C#. The 2023 FAQ copy also lists C, C++ and Visual Basic 6.0 / .NET; the same structure carries over, but you will need your language's own file and database APIs.
Try the whole brief first. The reference is one correct approach, not the only one, and reading it early removes most of the practice value.
09 Exam-day habits
- Work without internet search to simulate exam conditions.
- Type the sample input yourself and compare your output line by line before you look at the reference.