Java Reference
In-Depth Information
88
// return commission rate
89
public double getCommissionRate()
90
{
91
return commissionRate;
92
}
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110 // calculate earnings
111 public double earnings()
112 {
113
114 }
115
116 // return String representation of BasePlusCommissionEmployee
117 @Override
118 public String toString()
119 {
120 return String.format(
121 "%s: %s %s%n%s: %s%n%s: %.2f%n%s: %.2f%n%s: %.2f" ,
122 , firstName, lastName,
123 "social security number" , socialSecurityNumber,
124 "gross sales" , grossSales, "commission rate" , commissionRate,
125
// set base salary
public void setBaseSalary( double baseSalary)
{
if (baseSalary < 0.0 )
throw new IllegalArgumentException(
"Base salary must be >= 0.0" );
this .baseSalary = baseSalary;
}
// return base salary
public double getBaseSalary()
{
return baseSalary;
}
return baseSalary + (commissionRate * grossSales);
"base-salaried commission employee"
"base salary" , baseSalary
);
126 }
127 } // end class BasePlusCommissionEmployee
Fig. 9.6 | BasePlusCommissionEmployee class represents an employee who receives a base
salary in addition to a commission. (Part 3 of 3.)
Class BasePlusCommissionEmployee does not specify “ extends Object ” in line 5, so
the class implicitly extends Object . Also, like class CommissionEmployee 's constructor
(lines 13-34 of Fig. 9.4), class BasePlusCommissionEmployee 's constructor invokes class
Object 's default constructor implicitly , as noted in the comment in line 19.
Class BasePlusCommissionEmployee 's earnings method (lines 111-114) returns the
result of adding the BasePlusCommissionEmployee 's base salary to the product of the
commission rate and the employee's gross sales.
Class BasePlusCommissionEmployee overrides Object method toString to return a
String containing the BasePlusCommissionEmployee 's information. Once again, we use
Search WWH ::




Custom Search