//
// HourlyEmployee.java
// Represents an employee paid at an hourly rate
//
// Nadeem Abdul Hamid
// CSC 121 - Berry College
//

public class HourlyEmployee extends Employee {

    private double hourlyWage;      // pay per hour
    private double hoursWorked;    // hours worked per week

    // four-argument constructor
    public HourlyEmployee( String name, String ssn, double wage, double hours ) {
	super( name, ssn );
	setWage( wage );
	setHours( hours );
    }

    // validate and set wage
    public void setWage( double wage ) {
        hourlyWage = wage < 0.0 ? 0.0 : wage;
    }

    // return hourly wage
    public double getWage() { return hourlyWage; }

    // validate and set hours worked per week
    public void setHours( double hours ) {
        // maximum 168 hours in a week (7 * 24)
        hoursWorked = ( hours >= 0.0 && hours <= 168 )
	    ? hours : 0.0;
    }

    // return hours worked per week
    public double getHours() { return hoursWorked; }

    // calculate earnings (override abstract method in superclass)
    public double earnings() { 
        if ( getHours() <= 40 ) // no overtime
            return getWage() * getHours(); 
        else
            return 40 * getWage() + ( getHours() - 40 ) * getWage() * 1.5;
    } // end method earnings
    
    // return String representation of SalariedEmployee object
    public String toString() {
        return "hourly employee: " + super.toString()
	    + "\nhourly wage: " + getWage()
	    + "\nhours worked: " + getHours();
    } // end method toString

} // end class HourlyEmployee