THE HourlyEmployeeDriver CLASS


In this lab you will develop a driver program for the HourlyEmployee class.

A Driver for the HourlyEmployee Class

This lab deals with the creation of a driver program to test each of the methods in a class. As noted in Chapter 2, a production-strength driver that permits all of a class's methods to be tested extensively is more complex than an ad hoc driver for a single method. In this lab, you will piece together a driver for the HourlyEmployee class from Lab 1.

Here is the current version of the HourlyEmployee class. The code shows the default constructor, the constructor with a String parameter and the makesMoreThan method. As you can see, HourlyEmployee extends FullTimeEmployee and also implements Employee. HourlyEmployee inherits the toString method from FullTimeEmployee.

import java.util.*;

public class HourlyEmployee extends FullTimeEmployee implements Employee
{
    protected int hoursWorked;

    protected double payRate;    


    /**
     *  Initializes this HourlyEmployee object to have an empty string for
     *  the name, 0 for hours worked, 0.00 for the pay rate and 0.00 for
     *  grossPay.
     *
     */
    public HourlyEmployee()
    {
	hoursWorked = 0;
	payRate = 0.00;
	grossPay = 0.00;
    } // default constructor


    
    /**
     *  Initializes this HourlyEmployee object's name and gross pay from a
     *  a specified String object, which consists of a name, hours worked and
     *  pay rate, with at least one blank between each of those three 
     *  components.
     *
     *  @param s - the String object from which this HourlyEmployee object
     *                 is initialized.
     *
     */ 
    public HourlyEmployee (String s) 
    {
	StringTokenizer tokens = new StringTokenizer (s);
	name = tokens.nextToken();
	hoursWorked = Integer.parseInt (tokens.nextToken());
	payRate = Double.parseDouble (tokens.nextToken());

	grossPay = hoursWorked * payRate;
    } // constructor with string parameter     	


    /**
     *   Determines if this HourlyEmployee object's gross pay is greater than
     *   a specified Employee object's gross pay.
     *
     *  @param otherEmployee - the specified Employee object whose
     *         gross pay this HourlyEmployee object's gross pay is compared to.
     *  @return true - if this HourlyEmployee object did not work any overtime,
     *                 otherEmployee is a FullTimeEmployee object, and this   
     *                 HourlyEmployee object's gross pay is greater than
     *                 otherEmployee's gross pay.  Otherwise, return false.
     *                  
     */
    public boolean makesMoreThan (Employee otherEmployee)
    {
        final int MAX_NORMAL_HOURS = 40;
                 
        return hoursWorked <= MAX_NORMAL_HOURS && 
               super.makesMoreThan (otherEmployee);
    } // method makesMoreThan

} // class HourlyEmployee

The driver class will be tested with a file in which each line represents a method call; the calling object will be either e1 or e2, both of which are of type HourlyEmployee. For example, we might have

e1 HourlyEmployee Jager 35 10.00
to represent the method call

e1 = new HourlyEmployee ("Jager 35 10.00");