public class CommissionEmployee3
1: // Fig. 9.12: CommissionEmployee3.java
2: // CommissionEmployee3 class represents a commission employee.
3:
4: public class CommissionEmployee3
5: {
6: private String firstName;
7: private String lastName;
8: private String socialSecurityNumber;
9: private double grossSales; // gross weekly sales
10: private double commissionRate; // commission percentage
11:
12: // five-argument constructor
13: public CommissionEmployee3( String first, String last, String ssn,
14: double sales, double rate )
15: {
16: // implicit call to Object constructor occurs here
17: firstName = first;
18: lastName = last;
19: socialSecurityNumber = ssn;
20: setGrossSales( sales ); // validate and store gross sales
21: setCommissionRate( rate ); // validate and store commission rate
22: } // end five-argument CommissionEmployee3 constructor
23:
24: // set first name
25: public void setFirstName( String first )
26: {
27: firstName = first;
28: } // end method setFirstName
29:
30: // return first name
31: public String getFirstName()
32: {
33: return firstName;
34: } // end method getFirstName
35:
36: // set last name
37: public void setLastName( String last )
38: {
39: lastName = last;
40: } // end method setLastName
41:
42: // return last name
43: public String getLastName()
44: {
45: return lastName;
46: } // end method getLastName
47:
48: // set social security number
49: public void setSocialSecurityNumber( String ssn )
50: {
51: socialSecurityNumber = ssn; // should validate
52: } // end method setSocialSecurityNumber
53:
54: // return social security number
55: public String getSocialSecurityNumber()
56: {
57: return socialSecurityNumber;
58: } // end method getSocialSecurityNumber
59:
60: // set gross sales amount
61: public void setGrossSales( double sales )
62: {
63: grossSales = ( sales < 0.0 ) ? 0.0 : sales;
64: } // end method setGrossSales
65:
66: // return gross sales amount
67: public double getGrossSales()
68: {
69: return grossSales;
70: } // end method getGrossSales
71:
72: // set commission rate
73: public void setCommissionRate( double rate )
74: {
75: commissionRate = ( rate > 0.0 && rate < 1.0 ) ? rate : 0.0;
76: } // end method setCommissionRate
77:
78: // return commission rate
79: public double getCommissionRate()
80: {
81: return commissionRate;
82: } // end method getCommissionRate
83:
84: // calculate earnings
85: public double earnings()
86: {
87: return getCommissionRate() * getGrossSales();
88: } // end method earnings
89:
90: // return String representation of CommissionEmployee3 object
91: public String toString()
92: {
93: return String.format( "%s: %s %s\n%s: %s\n%s: %.2f\n%s: %.2f",
94: "commission employee", getFirstName(), getLastName(),
95: "social security number", getSocialSecurityNumber(),
96: "gross sales", getGrossSales(),
97: "commission rate", getCommissionRate() );
98: } // end method toString
99: } // end class CommissionEmployee3
100:
101:
102: /**************************************************************************
103: * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
104: * Pearson Education, Inc. All Rights Reserved. *
105: * *
106: * DISCLAIMER: The authors and publisher of this book have used their *
107: * best efforts in preparing the book. These efforts include the *
108: * development, research, and testing of the theories and programs *
109: * to determine their effectiveness. The authors and publisher make *
110: * no warranty of any kind, expressed or implied, with regard to these *
111: * programs or to the documentation contained in these books. The authors *
112: * and publisher shall not be liable in any event for incidental or *
113: * consequential damages in connection with, or arising out of, the *
114: * furnishing, performance, or use of these programs. *
115: *************************************************************************/