Site MapHelpFeedbackNumerical Data
Numerical Data


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.

O b j e c t i v e s

After you have read and studied this chapter, you should be able to

Select proper types for numerical data.

Write arithmetic expressions in Java.

Evaluate arithmetic expressions, following the precedence rules.

Describe how the memory allocation works for objects and primitive data values.

Write mathematical expressions, using methods in the Math class.

Use the GregorianCalendar class in manipulating date information such as year, month, and day.

Use the DecimalFormat class to format numerical data.

Convert input string values to numerical data.

Input numerical data by using System.in and output numerical data by using System.out.

Apply the incremental development technique in writing programs.

(Optional) Describe how the integers and real numbers are represented in memory.







WuOnline Learning Center

Home > Chapter 3