      1  /**

      2     An hourly employee is paid for every hour worked.

      3  */

      4  public class HourlyEmployee extends Employee

      5  {

      6     private double hourlyWage;

      7

      8     /**

      9        Constructs an hourly employee with a given name and weekly wage.

     10        @param name the name of this employee

     11        @param wage the hourly wage

     12     */

     13     public HourlyEmployee(String name, double wage)

     14     {

     15        setName(name);

     16        hourlyWage = wage;

     17     }

     18

     19     public double weeklyPay(int hoursWorked)

     20     {

     21        double pay = hoursWorked * hourlyWage;

     22        if (hoursWorked > 40)

     23        {

     24           // Add overtime

     25           pay = pay + ((hoursWorked - 40) * 0.5) * hourlyWage;

     26        }

     27        return pay;

     28     }

     29  }

     30