Java Reference
In-Depth Information
Introduction
Manipulating data is integral to creating useful computer programs.
Programmers must know how to retrieve and store different kinds of data
efficiently. Data are collections of raw facts or figures, such as words, text, or
numbers, which are used in reasoning or calculations (datum is the singular
form of the word, data). A computer program performs operations on input
data to produce output in the form of information The data used by a program
can come from a variety of sources, such as the program itself, from users of the
program, or from external files. When developing programs, programmers often
embed certain kinds of data, such as constant values that will not change, within
the program. Other kinds of data, such as current rates or prices that can
change, are input to the program from external files or by users.
In this chapter, you will learn about the numerous ways Java can accept,
retrieve, and manipulate data. You will learn how to write code that assigns
values to variables, which Java uses to store data temporarily for processing.
You also will learn to use classes and methods to set fields to specific values and
create instances of classes. As you develop an interactive console application, you
will learn to write code to accept a stream of character input from a keyboard,
read the line, and then process it. In addition, you will learn how to code formu-
las with mathematical operators and create a single line of output on the display.
In the process of modifying the console application to accept data from a dialog
box, you will learn to add Java's Swing components, such as JOptionPane, to
an interface to display messages and accept user input via dialog boxes. In
converting the application to an interactive applet, you will learn to use an
ActionListener to handle events, as well as to call constructors to add Labels,
TextFields, and a Button component to the interface, along with an Image.
Finally, you will create an HTML host file and then run the applet in the Applet
Viewer window.
Chapter Three — The Body Mass Index Calculator
The programs developed in this chapter create a Body Mass Index Calculator
for a health club and its staff of trainers to use as they work with health club
customers to establish exercise and diet regimens. Body mass index (BMI) is
one way to gauge the total body fat in adults by measuring the relationship of
weight to height. Studies have shown that adults should strive to maintain a BMI
between 20 and 24. The fitness center wants to measure improvement in its
customers by taking a before and after measurement of the customer's BMI. The
Body Mass Index Calculator will allow the trainers to input data and generate
accurate and consistent computerized calculations. To make it easily accessible
from any location in the fitness center, the Body Mass Index Calculator will be
available on a notebook computer, over the Web, or via a personal digital
assistant (PDA).
The compiled Java source code for the Body Mass Index Calculator will
cause prompts to display and will accept user input. The program then will cal-
culate the body mass index. Three versions of the Body Mass Index Calculator
are developed in this chapter: (1) a console application with input and output
Search WWH ::




Custom Search