Assignment 6: Guide – SWE 619 – ALL – Spring 2010

 

Goal: Polymorphism

 

Basic Assignment

 

For this assignment we are going to utilize a provided abstract class Employee, which is shown below:

 

public abstract class Employee {

    private String firstName;

    private String lastName;

   

    // Constructor

    public Employee(String first, String last) {

        firstName = first;

        lastName = last;

    }

   

    // Return the first name

    public String getFirst() {

        return firstName;

    }

   

    // Return the last name

    public String getLastName() {

        return lastName;

    }

    

    public String toString() {

        return firstName + ' ' + lastName;}

   

    // Abstrace method that must be implemented for each

    // derived class of Employee from which objects

    // are instantiated

   

    public abstract double earnings();

}

 

We will use the above abstract class to develop a payroll system using polymorphism. You will develop four types of employees for this assignment:

 

·         Boss – paid a fixed weekly salary regardless of the number of hours worked;

·         CommissionWorker – paid a flat base salary plus a percentage of sales;

·         PieceWorker – paid by number of items produced; and

·         HourlyWorker – paid by the hour and receives overtime pay.

 

It is a requirement to implement all of the above subclasses so that than cannot be inherited from again.

 

You can use the following Test class to assist you in designing your implementation classes:

 

public class Test {

    public static void main(String args[]){

        Employee ref;                   // superclass refernce

       

        Boss b = new Boss("Gabriella", "Parks", 800.00); 

        // first, last, weekly salary

       

        CommissionWorker c = new CommissionWorker("George", "Lackey ", 400.0, 3.0, 150);      

        // first, last, flat base weekly salary, amount per item sold, totalitems sold for week

       

        PieceWorker p = new PieceWorker("Robert", "Fullbrush", 2.5, 200);

        // first, last, wage per piece output, output per week

       

        HourlyWorker h = new HourlyWorker("Gillian", "Ponte", 13.74, 40);

        // first, last, wage per hour, hours worked for week

       

       

        // provide the remaining implementation to print the results

        // for validating your implementation

    }

}

 

For this assignment you will need to submit the following:

 

·         Implementation files: Employee.java; Boss.java; CommissionWorker.java; PieceWorker.java; Hourly.java; [5 points]

·         Implementation file and output for Test.java; [1 points]

·         Implementation of JUnit files; [2 points] and

·         Half page description that describes how the “ref” variable in class Test is utilize to effect polymorphic behavior. [2points]