Up to this point, our lablets have produced
user interfaces that look great on the screen, and even look like
they might be easy to use. Unfortunately, we haven't been able
to use them to do anything. That, of course, was due to the fact that
we had not yet written Java code to produce and control the behavior
of applets, other than those statements required to draw and place
interface elements on the screen. In this chapter we will examine more
closely the basic statements that are the building blocks of
Java programs, many of which we've seen already, but haven't
considered in any detail. We'll experiment with, for example, some of
Java's built-in data types and operators, its String
class, a variety of assignment and selection statements, and
the issue of visibility to discover why our applets are written
as they are.
The
lablet for this chapter simulates a simple soda machine, and does so in
behavior as well as appearance. You insert coins and select a brand
by clicking buttons. The machine lets you know when it dispenses a
drink, returns change when asked to do so, and even indicates when it
is out of a certain brand. In short, this program uses Java statements to
produce our first truly interactive program.
![]() |
In this lab, you will: | ||
![]() |
Run and experiment with
the |
||
![]() |
Modify |
||
![]() |
Extend the soda machine's performance by modifying the program's existing methods, and adding new classes. |
myCount
, is even by using an if
statement like if ((myCount % 2) == 0)
.