Java Reference
In-Depth Information
Using Word Wrapping in TextPad
In general, you can break a long line of code by pressing the
ENTER key after a comma delimiter in the code. Pressing the ENTER
key at other places in long lines of code will cause a compile error
message to display. Alternatively, you can set TextPad to wrap long
lines in the coding window by pressing CTRL + Q and then pressing
W. To set TextPad to wrap long lines permanently, click Preferences
on the Configure menu. When TextPad displays the Preferences
dialog box, click the plus sign next to Document Classes, click
Java, and then click the Word wrap long lines check box.
The Commission program now has two internal methods, main() and
getSales(). User-defined methods such as getSales() must contain a method
header and a set of braces. The only other requirement is that they reside inside
a class. Incorrect placement of methods will generate compile errors. In this
application, the getSales() method is placed outside of the main() method but
within the braces of the Commission class.
Testing the getSales() Method
The following steps test the stub of the getSales() method by compiling and
running the source code.
To Compile and Test the getSales() Method
1. With the Data Disk in drive A, compile the program by clicking Compile
Java on the Tools menu. If TextPad notifies you of errors, click
Commission.java in the Selector window, fix the errors, and then
compile again. When the program compiles with no errors, click Run
Java Application on the Tools menu.
2. When the Input dialog box displays, type 500 in the text box.
Entering the test value of 500 confirms that the getSales() method accepts
the value input by the user (Figure 4-11).
Input
dialog box
message prompts
user to enter
sales amount
text box
OK button
FIGURE 4-11
 
Search WWH ::




Custom Search