18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Inheritance 165<br />

• For an object o which is an <strong>in</strong>stance of a derived class, how does a programmer call the method m <strong>in</strong><br />

the base class which has been overloaded by another method m <strong>in</strong> the derived class?<br />

• Why can the code of F<strong>in</strong>alization <strong>in</strong> the class Account_At not be called twice?<br />

10.11 Exercises<br />

Construct the follow<strong>in</strong>g:<br />

• Employee_Pay<br />

A class Employee_Pay which represents a person’s salary has the follow<strong>in</strong>g methods:<br />

Method<br />

Responsibility<br />

Set_hourly_rate Set the hourly rate.<br />

Add_hours_worked Accumulate the number of hours worked so far.<br />

Pay<br />

Deliver the pay for this week.<br />

Reset<br />

Reset the hours worked back to zero.<br />

Hours_Worked Deliver the number of hours worked so far this<br />

week.<br />

Pay_rate<br />

Deliver the hourly pay rate.<br />

Tax is to be deducted at 20% of total pay.<br />

• Test<br />

A program to test the class Employee_Pay.<br />

• Better_Employee_Pay<br />

A class Better_Employee_Pay which represents a person’s salary. This extends the class<br />

Employee_Pay to add the additional methods of:<br />

Method<br />

Responsibility<br />

Set_Overtime_Pay Set the overtime pay rate.<br />

Normal_Pay_Hours Set the number of hours <strong>in</strong> a week that have to be<br />

worked before the overtime pay rate is applied.<br />

Pay<br />

Deliver the pay for this week. This will consist of<br />

the hours worked at the normal pay rate plus the<br />

hours worked at the overtime rate.<br />

• Test<br />

A program to test the class Better_employee_pay.<br />

• Employee_Pay_With_Repayment.<br />

A class Employee_Pay_With_Repayment which represents a person’s salary after the deduction<br />

of the weekly repayment of part of a loan for travel expenses. This extends the class<br />

Better_employee_pay to add the additional methods of:<br />

Method<br />

Set_Deduction<br />

Pay<br />

Responsibility<br />

Set the weekly deduction<br />

Deliver the pay for this week. This will <strong>in</strong>clude<br />

the deduction of the money for the employee<br />

loan if possible.<br />

Remember to <strong>in</strong>clude the possibility of an employee not be<strong>in</strong>g able to repay the weekly repayment of<br />

their loan as they have not worked enough hours.<br />

• test<br />

A program to test the class Employee_Pay_With_Repayment.<br />

© M A Smith - May not be reproduced without permission

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!