Java Reference
In-Depth Information
Notice that the matching brace 13 lines below is outlined in gray. Because Java uses so many braces and
parentheses, this is an extremely helpful RAD feature.
3.
Move the cursor before the brace.
Notice that the matching brace is not highlighted anymore. To display a paired symbol's matching symbol,
the cursor must be placed after the symbol.
4.
In the following statement, click to the right of the last parenthesis:
if ((taxSal > 50) && (taxSal <= 150))
Notice that the matching parenthesis after the if is outlined in gray.
5.
Move the cursor one character to the left.
The parenthesis following the && is now highlighted.
Great, we have the calculation, now we need to test that it is correct. We will code a series of “test cases” in the
main method. Once we are satisfied that the calculation is correct, we will then modify the rest of the application to
use this new feature.
6.
After the println statement in the main method, add these four statements:
System.out.println(emp.fedTaxCalc(15.50, 0));
System.out.println(emp.fedTaxCalc(30.75, 0));
System.out.println(emp.fedTaxCalc(7.75, 0));
System.out.println(emp.fedTaxCalc(7.75, 3));
There are many strategies for testing. A simple one is to ensure that every condition and calculation is tested at
least once. These added pay rates will test many of the conditions but not all.
7.
Save the Employee source and run Employee as a Java application.
Based on the results, is the application ready? Can you explain the results?
Debugging
There are many different types of errors: syntax errors, compilation errors, and runtime errors. RAD will identify the
first two types but is not smart enough to catch the third type of error. Runtime errors can occur for many different
reasons: logic errors, user input errors, missing resources (e.g., a required data file is not available), and security
(e.g., the application doesn't have authority to a required data file) are only a few of the possibilities. Fortunately, most
source code editors provide two tools to find logic errors: breakpoints and stepping.
Breakpoints are statements that when reached during program execution will temporarily halt program
execution. Once a breakpoint is reached, stepping allows the programmer to control when the next statement(s) will
be executed. Both of these capabilities are provided by RAD in the Debug perspective.
In case you didn't notice, there is a major problem with the test results: the values are all incorrect. For instance,
the very first test is for a pay rate of 15.50 per hour. For a forty-hour work week this results in a gross salary of $620 per
week. Our calculation is returning a tax amount of $489.50. That seems a little steep, don't you think? On top of that,
the example is for two exemptions, which decreases the taxable amount by $120 for a total taxable amount of $500. So,
our calculation is saying that $489.50 of the taxable $500 is going to taxes.
Why get out of bed to go to work?
 
Search WWH ::




Custom Search