Tuesday, March 22, 2011

Week 4 Tutorial

Overview:
In this week’s exercise, you are implementing additional behaviour for the company to make use of the new concepts of inheritance and polymorphism. You will extend the program to allow for two different types of employees: TeamLeader and Programmer.

Each team leader has an annual salary. He/she is also being paid for overtime work based on the salary rate.

Every programmer is on contract. He/she maintains a contract start date and a contract end date. As a contract worker, he/she is being paid hourly given a salary rate.

Every employee is paid superannuation on top of the salary. For the programmers, the superannuation is 5% (0.05) of the salary. For the team leaders, it is 10% (0.1).

Tasks:
  1. Create two new classes TeamLeader and Programmer, which inherit from the Employee class, based on the overview description above. Include in each class: 
    • a constructor with default values,
    • at least one constructor with parameters,
    • corresponding accessor and mutator methods for ALL attributes; and
    • a toString method, which returns a string of object’s details
  2. In the TeamLeader class, provide one additional method: 
    • CalculateSalary, which takes an integer as a parameter. The parameter represents the number of overtime hours worked per month. The method returns the total salary earned per month. The formula is:
      Monthly salary = annual salary/12 + number of overtime hours per month * salary rate
  3. In the Programmer class, provide two additional methods
    • noOfDaysLeft, which takes no parameter and returns an integer. The formula for number of days left on the contract is:
      Number of days left = Contract end date - Current date 
    • CalculateSalary, which takes one integer parameter representing the number of hours worked per month and returns the salary:
      Monthly salary = number of hours per month * salary rate
  4. For all employees, provide a method to calculate the superannuation amount per month. The formula is:
    Monthly superannuation = monthly salary * rate
  5. In the main method of the Company class,
    • Create a number of team leaders and programmers and add them to the ArrayList of employees (Polymorphism!)
    • Create a number of teams and projects, based on the team leaders and programmers created.
    • Print the detailed information of all employees including their monthly salaries and the corresponding monthly superannuations. For each programmers, display also the number of days left in his/her contracts

Hint: Use the super keyword where appropriate

No comments:

Post a Comment