// Fig. 10.4: CommissionEmployee.cs // CommissionEmployee class represents a commission employee. public class CommissionEmployee : object { private string firstName; private string lastName; private string socialSecurityNumber; private decimal grossSales; // gross weekly sales private decimal commissionRate; // commission percentage // five-parameter constructor public CommissionEmployee( string first, string last, string ssn, decimal sales, decimal rate ) { // implicit call to object constructor occurs here firstName = first; lastName = last; socialSecurityNumber = ssn; GrossSales = sales; // validate gross sales via property CommissionRate = rate; // validate commission rate via property } // end five-parameter CommissionEmployee constructor // read-only property that gets commission employee's first name public string FirstName { get { return firstName; } // end get } // end property FirstName // read-only property that gets commission employee's last name public string LastName { get { return lastName; } // end get } // end property LastName // read-only property that gets // commission employee's social security number public string SocialSecurityNumber { get { return socialSecurityNumber; } // end get } // end property SocialSecurityNumber // property that gets and sets commission employee's gross sales public decimal GrossSales { get { return grossSales; } // end get set { grossSales = ( value < 0 ) ? 0 : value; } // end set } // end property GrossSales // property that gets and sets commission employee's commission rate public decimal CommissionRate { get { return commissionRate; } // end get set { commissionRate = ( value > 0 && value < 1 ) ? value : 0; } // end set } // end property CommissionRate // calculate commission employee's pay public decimal Earnings() { return commissionRate * grossSales; } // end method Earnings // return string representation of CommissionEmployee object public override string ToString() { return string.Format( "{0}: {1} {2}\n{3}: {4}\n{5}: {6:C}\n{7}: {8:F2}\n{9}: {10:C}", "commission employee", FirstName, LastName, "social security number", SocialSecurityNumber, "gross sales", GrossSales, "commission rate", CommissionRate, "earnings", Earnings() ); } // end method ToString } // end class CommissionEmployee /************************************************************************** * (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. * *************************************************************************/