Java Reference
In-Depth Information
2. Enter lines 106 through 113 as shown in Figure 4-30 on the previous
page.
TextPad displays the output() method in the coding window (Figure 4-32).
defines pattern
for formatting
numeric output
output()
method
twoDigits.format()
method applies
pattern to sales
and commission
values
FIGURE 4-32
The DecimalFormat class contains many useful methods to change numeric
formatting symbols. For example, instead of formatting a number in the form:
4,200,923.25
Some European countries use different numeric conventions, such as using a
comma instead of a period to separate decimal values and a period instead of a
comma as the grouping or thousands separator, in the form:
4.200.923,25
The DecimalFormat class offers a great deal of flexibility in the formatting of
numbers.
The finish() Method
Finally, the main() method must call the finish() method to exit the system
when the program is completed successfully. The complete main() method dis-
plays in Figure 4-33, including a call to the finish() method in line 26.
15
public static void main ( String [] args )
16
{
17
//declare class variables
18
double dollars, answer;
19
int empCode;
20
21
//call methods
22
dollars = getSales () ;
23
empCode = getCode () ;
24
answer = getComm ( dollars,empCode ) ;
25
output ( answer, dollars ) ;
26
finish () ;
27
}
28
FIGURE 4-33
 
Search WWH ::




Custom Search