Java Reference
In-Depth Information
Introduction
This chapter illustrates how to create an object, complete with methods and
data, for use in other programs. Recall that Java can store data about objects and
that it uses coded methods to trigger operations. An object has three key charac-
teristics: (1) identity , which means the object can be called and used as a single
unit; (2) state , which refers to the various properties of the object, whose values
might change; and (3) behavior , which means the object can perform actions
and can have actions performed on it.
This chapter also shows how to create different kinds of storage locations other
than single variables that hold one piece of data. Storing and then manipulating
a single value is useful for some applications, but many times a program must deal
with larger amounts of data. Manipulating large numbers of variables with individ-
ual identifiers is cumbersome and tedious. Thus, Java allows programmers to
organize and process data systematically using an array , which stores multiple
data items of the same data type in a single storage location. Programmers use
counter-controlled loops to accomplish many of the array manipulations.
Finally, in the process of creating a windowed application, this chapter
introduces four new AWT components: Frame, Panel, TextArea, and Choice
components. The AWT components will be placed precisely in the windowed
application using a layout manager — one of a set of five classes that help pro-
grammers organize components into predefined locations in the window.
Chapter Five — Reservations
The Mahalo Polynesian Restaurant takes reservations during the day for evening
use of their eight party rooms. Five of the rooms are for nonsmoking customers,
and three of the rooms are for smoking customers. Rooms are reserved for
groups of eight or more for the entire evening; there is a maximum of 20 guests
per party room. The restaurant only accepts same-day reservations. When a
reservation is taken, the customer is asked for a name, a phone number, a smok-
ing preference, and the number of people in the party.
The restaurant wants a stand-alone application that allows the user to book
a room and provides the capability to see, at a glance, which rooms are open and
which ones are reserved. The Reservations program, as shown in Figure 5-1, is
developed in this chapter as a stand-alone windowed application with a
graphical user interface that displays a representation of the rooms and provides
data input fields allowing the user to reserve a room for a party.
Search WWH ::




Custom Search