Java Reference
In-Depth Information
public int getCount()
//Method to show the number of items in the dispenser
//Postcondition: The value of the instance variable
//
numberOfItems is returned
public int getProductCost()
//Method to show the cost of the item
//Postcondition: The value of the instance
//
variable cost is returned
public void makeSale()
//Method to reduce the number of items by 1
//Postcondition: numberOfItems = numberOfItems - 1;
Dispenser
-numberOfItems: int
-cost: int
+Dispenser()
+Dispenser( int , int )
+getCount(): int
+getProductCost(): int
+makeSale(): void
8
FIGURE 8-20 UML class diagram of the class Dispenser
Because the candy machine sells four types of items, we will create four objects of
type Dispenser . The statement:
Dispenser chips = new Dispenser(100, 65);
creates the object chips , sets the number of chip bags in this dispenser to 100 , and
sets the cost of each chip bag to 65 cents (see Figure 8-21).
numberOfItems 100
chips
cost 65
FIGURE 8-21 The object chips
Search WWH ::




Custom Search