Java Reference
In-Depth Information
That wasn't too hard was it? Notice that the null constructor does nothing. However, the class variables, defined
before the constructor will be created.
7.
In the fedTaxCalcFormatted method, remove the statement that defines taxAmt and
change the two other references to taxAmt to stringTaxAmt. The method should look like
the following:
public String fedTaxCalcFormatted(double payRate,
int exemptions){
stringTaxAmt = cf.format(this.fedTaxCalc(payRate,
exemptions));
return stringTaxAmt;
}
Essentially, we substituted the global (i.e., class) variable stringTaxAmt (created in Step 1) for the method variable
taxAmt. We will now put it to good use in a new method.
8.
Before the already existing method of the same name, add the following method:
public String fedTaxCalcFormatted(){
this .fedTaxCalcFormatted( this .payRate, this .exemptions);
return stringTaxAmt;
}
Notice that this method expects no parameters. Instead, the method uses the Employee object's payRate and
exemptions properties (i.e., to supply those values to the fedTaxCalcFormatted method). Also, notice that no variable
is needed to receive the result (a string) returned by the fedTaxCalcFormatted method. Because these methods are
within the same class, the global variable stringTaxAmt can hold the result and be returned by both methods.
9.
In the grossSalaryCalcFormatted method, remove the statement that defines the string
grossSalaryFormatted and change the two other references to grossSalaryFormatted to
stringGrossSalary.
The method should look like the following:
public String grossSalaryCalcFormatted( double payRate) {
this .grossSalaryCalc(payRate);
stringGrossSalary = cf.format(doubleGrossSalary);
return stringGrossSalary;
}
We created a global variable stringGrossSalary earlier and have substituted it for the method variable
grossSalaryFormatted.
10.
Before the already existing method of the same name, add the following method:
public String grossSalaryCalcFormatted() {
this .grossSalaryCalcFormatted( this .payRate);
return stringGrossSalary; }
As with the fedTaxCalcFormatted method, we used the Employee object's properties and a global variable
(instead of a method variable) to simplify using this class. Now we need to change the EnterEmpInfo class to use the
new methods.
 
Search WWH ::




Custom Search