// Fig. 11.6: HourlyEmployee.cs // HourlyEmployee class that extends Employee. public class HourlyEmployee : Employee { private decimal wage; // wage per hour private decimal hours; // hours worked for the week // five-parameter constructor public HourlyEmployee( string first, string last, string ssn, decimal hourlyWage, decimal hoursWorked ) : base( first, last, ssn ) { Wage = hourlyWage; // validate hourly wage via property Hours = hoursWorked; // validate hours worked via property } // end five-parameter HourlyEmployee constructor // property that gets and sets hourly employee's wage public decimal Wage { get { return wage; } // end get set { wage = ( value >= 0 ) ? value : 0; // validation } // end set } // end property Wage // property that gets and sets hourly employee's hours public decimal Hours { get { return hours; } // end get set { hours = ( ( value >= 0 ) && ( value <= 168 ) ) ? value : 0; // validation } // end set } // end property Hours // calculate earnings; override Employee's abstract method Earnings public override decimal Earnings() { if ( Hours <= 40 ) // no overtime return Wage * Hours; else return ( 40 * Wage ) + ( ( Hours - 40 ) * Wage * 1.5M ); } // end method Earnings // return string representation of HourlyEmployee object public override string ToString() { return string.Format( "hourly employee: {0}\n{1}: {2:C}; {3}: {4:F2}", base.ToString(), "hourly wage", Wage, "hours worked", Hours ); } // end method ToString } // end class HourlyEmployee /************************************************************************** * (C) Copyright 1992-2006 by Deitel & Associates, Inc. and * * Pearson Education, Inc. All Rights Reserved. * * * * DISCLAIMER: The authors and publisher of this book have used their * * best efforts in preparing the book. These efforts include the * * development, research, and testing of the theories and programs * * to determine their effectiveness. The authors and publisher make * * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * * and publisher shall not be liable in any event for incidental or * * consequential damages in connection with, or arising out of, the * * furnishing, performance, or use of these programs. * *************************************************************************/