Java Reference
In-Depth Information
Rectangle
length
width
setLength
setWidth
getLength
getWidth
computePerimeter
computeArea
print
FIGURE 6-13 class Rectangle with data members and operations
6
With these steps completed, you can design an algorithm for each operation of an object
(class) and implement each algorithm in Java.
The diagram in Figure 6-13 is a form of a diagram known as the class unified modeling
language (UML) diagram. After introducing a fewmore terms used in a class UML diagram, we
formally introduce the class UML diagram in Chapter 8, when we discuss classes in general.
EXAMPLE 6-3
Consider the following problem:
A place to buy candy is from a candy machine. A new candy machine is purchased for
the cafeteria, but it is not working properly. The candy machine has four dispensers to
hold and release items sold by the candy machine as well as a cash register. The
machine sells four products—candies, chips, gum, and cookies—each stored in a
separate dispenser. You have been asked to write a program for this candy machine so
that it can be put into operation.
The program should do the following:
￿ Show the customer the different products sold by the candy machine.
￿ Let the customer make the selection.
￿ Show the customer the cost of the item selected.
￿ Accept the money from the customer.
￿ Return the change.
￿
Release the item, that is, make the sale.
 
Search WWH ::




Custom Search