Java Reference
In-Depth Information
7.
Save EnterEmpInfo and run as an application.
8.
Enter 10.3338 for the payRate and 4 for the number of exemptions.
9.
Click the TaxAmt button.
The result will be the message: “Federal Tax amount is: $15.50”.
10.
Click the Gross button.
The result will be the message: “Gross Salary is: $413.3520.” So, the tax amount is being formatted correctly, but
we now need to format the gross salary amount.
11.
Click the Exit button and in Employee, add the following statement at the end of the class
variable definitions, to create a new class variable called doubleGrossSalary:
private double doubleGrossSalary;
In Employee, after the fedTaxCalc method, create two new methods called grossSalary
Calc and grossSalaryCalcFormatted as follows:
12.
public double grossSalaryCalc( double payRate){
doubleGrossSalary = payRate * 40;
return doubleGrossSalary;
}
public String grossSalaryCalcFormatted( double payRate) {
String grossSalaryFormatted = new String();
this .grossSalaryCalc(payRate);
grossSalaryFormatted = cf.format(doubleGrossSalary);
return grossSalaryFormatted;
}
13.
Save the Employee source code.
14.
In EnterEmpInfo's actionPerformed method, replace the following statements:
doubleGross = doubleEmpPR * 40;
resultLbl.setText("Gross Salary is: $" +
doubleGross + "0");
with:
Employee emp = new Employee("", "", "", "", "");
resultLbl.setText("Gross Salary is: " +
emp.grossSalaryCalcFormatted(doubleEmpPR));
Notice that this removes the gross salary calculation and substitutes a call to the Employee object's (emp's)
grossSalaryCalcFormatted method.
15.
Save EnterEmpInfo and run as an application.
16.
Enter 10.3338 for the payRate and 4 for the number of exemptions.
17.
Click the Gross button.
Search WWH ::




Custom Search