Java Reference
In-Depth Information
Figure 6-10.
The formula's individual operations are performed in the following order. First, the multiplication is
performed (150 * .15) resulting in:
taxAmt = 12 + taxSal - 22.5;
The addition is performed next ( 12 + taxSal) , resulting in:
taxAmt = 512 - 22.5;
Finally, the subtraction is done, resulting in:
taxAmt = 489.5;
This was not expected. The individual operations should have been executed as follows: subtract the already
taxed amount (150) from taxSal, calculate the additional tax amount, and add that amount to 12 (the tax amount on
the first 150 dollars of income). The formula should be:
taxAmt = (taxSal - 150) * .15 + 12;
There is actually another way that the formula can be specified. Can you figure it out?
Here's a debugging lesson that will save you a lot of time and aggravation in your programming future: if there is
an error in a statement, then similar statements are highly likely to contain errors and should also be checked. In this
case, it means you should review the other calculations for errors. Lo and behold, three of the other calculations are
also wrong.
9.
Close the Debug perspective, by right clicking the Debug perspective icon (on the far right
of the window) and selecting Close from the pop-up menu.
10.
Correct the formulas and save the Employee source code.
 
Search WWH ::




Custom Search