When we review the Ch2 Monogram sample program, we can visualize three tasks:
input, computation, and output. We view computer programs as getting input, performing
computation on the input data, and outputting the results of the computations.
The type of computation we performed in Chapter 2 is string processing. In
this chapter, we will study another type of computation, the one that deals with
numerical data. Consider, for example, a metric converter program that accepts
measurements in U.S. units (input), converts the measurements (computation), and
displays their metric equivalents (output). The three tasks are not limited to numerical
or string values, though. An input could be a mouse movement. Adrawing program
may accept mouse dragging (input), remember the points of mouse positions
(computation), and draw lines connecting the points (output). Selecting a menu item
is yet another form of input. For beginners, however, it is easiest to start writing
programs that accept numerical or string values as input and display the result of
computation as output.
We will introduce more standard classes to reinforce the object-oriented style
of programming. The Math class includes methods we can use to express mathematical
formulas. The DecimalFormat class includes a method to format numerical
data so we can display the data in a desired precision. The GregorianCalendar class
includes methods to manipulate the date. In Chapter 2, we performed String input
and output by using the standard input (Scanner) and output (System.out). We will
describe the input and output routines for numerical data in this chapter.
Finally, we will continue to employ the incremental development technique
introduced in Chapter 2 in developing the sample application, a loan calculator program.
As the sample program gets more complex, well-planned development steps
will smooth the development effort.
To learn more about the book this website supports, please visit its Information Center.