Java Reference
In-Depth Information
Introduction
This chapter illustrates how a Java program accepts and writes data to a file on a
secondary storage device, such as a disk. A data file is a collection of related facts
organized in a systematic manner. Data files do not have to be electronic. A tele-
phone book is an example of a data file that contains the names, addresses, and
telephone numbers of individuals and businesses in a community. In this chapter,
you will learn how to use Java to write data to a sequential data file. A sequential
data file , or sequential file , is a file composed of fields of data stored one after
another on a storage device. Each primitive data type has an associated write()
method from the DataOutputStream class that programmers use to transfer data
to a storage device.
Thus far, the programs discussed in this topic have manipulated only volatile
data. Volatile data , or electricity-dependent data, is stored in the computer's
memory only while electricity is being supplied to the computer and the pro-
gram is running. Once the computer is powered off, the data is erased.
Nonvolatile data is stored and can be retrieved later.
Chapter Eight — Crandall Power and Light
This chapter provides an introduction to working with sequential data files by
building a BillPayer program for the company Crandall Power and Light. The
company wants to automate its payment-collection service by standardizing its
user interface at all remote locations. The BillPayer
program needs to accept payment information from
users who pay their bills at remote locations, such as
grocery stores and banks.
The BillPayer program should accept the follow-
ing information from the user: account number, pay-
ment amount, first name, last name, address, city,
state, and zip code. When the user clicks the Submit
button, the program should verify that all fields are
complete (non-blank) and, if the data is valid, write
the fields to the sequential file. If a field is blank, a
message box should display alerting the user of the
incomplete field.
Figure 8-1 displays the data entry screen.
FIGURE 8-1
Program Development
The program development cycle for the Crandall Power and Light BillPayer
program consists of tasks that correspond to the six development cycle phases,
as shown in Table 8-1.
Analysis and Design
Figure 8-2 shows the requirements document that initiates the development
cycle for the Crandall Power and Light BillPayer program. The requirements
document specifies the reason for the request, lists the required inputs and
outputs, and describes the sequence of data entry.
Search WWH ::




Custom Search