Exercise: Payroll-Interfaces01 - Exercise

Contact Us or call 1-877-932-8228
Exercise: Payroll-Interfaces01 - Exercise

Exercise: Payroll-Interfaces01

Duration: 30 to 40 minutes.

It turns out that our hypothetical system is to be used for all payments our company makes, not just payroll checks, and things like invoices will be paid through the system as well.

  1. Create a finance package, and within it create an interface called Payable.
    • it should define the public String getPayInfo() method that our employee classes already implement.
  2. Specify that all the employee classes implement Payable.
  3. The Solutions/Payroll-Interfaces01 directory contains a package called vendors with a class named Invoice - copy this directory to your working directory.
  4. Modify the payroll program by adding an array inv of several invoices (you can just hard-code them).
  5. The Solutions/finance folder also contains a file named CheckPrinter.java - copy that into your finance package. The class has a printChecks(Payable[]) method that you can call twice, once for employees and again for invoices.

Solution:

Solutions/Payroll-Interfaces01/finance/Payable.java
package finance;

public interface Payable {	

	public String getPayInfo();

}

This interface declares the public String getPayInfo() method that our employee classes already implement.

Solution:

Solutions/Payroll-Interfaces01/employees/Employee.java
package employees;
import finance.Payable;

public class Employee extends Person implements Payable {

---- C O D E   O M I T T E D ----

}

The class has been marked as implementing Payable. Although it would not be required, we should mark the derived classes the same way, to have more self-documenting code.

Next