TCS3064 Object Oriented Programing TUTORIAL & LAB EXERCISE #5
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
TCS3064 Object Oriented Programing
TUTORIAL & LAB EXERCISE #5
1. The following UML class diagram represents the classes in ABC Airlines, where the Manager and Clerk classes are subclasses of the Employee class.
Employee |
empNo: int empName: String basicSalary: double ~ empCount : int |
+ constructors (no-arg and parameterized) + Set and Get methods for instance variables + calculateSalary(): double + toString(): String |
Manager |
|
Clerk |
level: String workingYears: int |
|
overtimeHours: int overtimeRate: double |
+ constructors (no-arg and parameterized) + Set and Get methods for all instance variables + calculateMonthlyAllowance(): double + calculateSalary(): double + toString(): String |
|
+ constructors (no-arg and parameterized) + Set and Get methods for all instance variables + calculateOvertimePay(): double + calculateSalary(): double + toString(): String |
The following additional information is provided:
· The static variable empCount in the Employee class should be incremented each time an Employee object (including objects of its subclasses) is created.
· The toString() method of each class should return a string containing the data field values with appropriate labels, one data field per line.
· For Manager,
o Manager levels are Top, Senior and Junior.
o Computation of a manager’s salary is as follows:
§ Monthly salary = basic salary + monthly allowance
The monthly allowance information for managers is as follows:
Level |
Top |
Senior |
Junior |
Monthly allowance per working year |
$100.00 |
$80.00 |
$50.00 |
· For clerk, the computation of monthly salary is as follows:
· Monthly salary = basic salary + overtime pay
· Overtime pay = overtime hours * overtime rate
(a) Implement all the classes. You may introduce additional variables and methods that will increase the reusability and maintainability of the classes.
(b) Write a test program that will create a polymorphic array to store 4 Employee objects and then display the output as shown below:
Manager: Employee number: 1120 Employee name: Eric Basic salary: RM5000.00 Level: Top Working years: 7 years Manager: Employee number: 1121 Employee name: Raymond Basic salary: RM4000.00 Level: Senior Working years: 5 years Manager: Employee number: 1122 Employee name: Calvin Basic salary: RM3000.00 Level: Junior Working years: 3 years Clerk: Employee number: 1123 Employee name: Donald Basic salary: RM1000.00 Overtime hours: 20 hours Overtime rate: RM1.50 |
2. How do we
(a) overload a method? Give an example.
(b) override a method? Give an example. (3 marks)
3. (a) List the 3 advantages of polymorphism. (3 marks)
(b) What is generic programming? (2 marks)
2022-11-11