Java Reference
In-Depth Information
Candy Machine
The
class
CandyMachine
has four dispensers and a cash register. You
can name the four dispensers by the items they store. Therefore, the candy machine has
five data members—four dispensers and a cash register.
Step 4: Identify the operations for each of the objects (classes).
The relevant verbs are show (selection), make (selection), show (cost), accept (money), return
(change), and make (sale).
The verbs show (selection) and make (selection) relate to the candy machine. The verbs
show (cost) and make (sale) relate to the dispenser. Similarly, the verbs accept (money) and
return (change) relate to the cash register.
Dispenser
The verb show (cost) applies to either printing or retrieving the value of the
data member
cost
. The verb make (sale) applies to reducing the number of items in the
dispenser by 1. Of course, the dispenser has to be nonempty. You must also provide an
operation to set the cost and the number of items in the dispenser. Thus, the operations
for a dispenser object are:
6
getCount
: Retrieve the number of items in the dispenser.
getProductCost
: Retrieve the cost of the item.
makeSale
: Reduce the number of items in the dispenser by 1.
setProductCost
: Set the cost of the product.
setNumberOfItems
: Set the number of items in the dispenser.
Cash Register
The verb accept (money) applies to updating the money in the cash register
by adding the money deposited by the customer. Similarly, the verb return (change)
applies to reducing the money in the cash register by returning the overpaid amount (by
the customer) to the customer. You also need to (initially) set the money in the cash
register and retrieve the money from the cash register. Thus, the possible operations on a
cash register are:
acceptAmount
: Update the amount in the cash register.
returnChange
: Return the change.
getCashOnHand
: Retrieve the amount in the cash register.
setCashOnHand
: Set the amount in the cash register.
Candy Machine
The verbs show (selection) and make (selection) apply to the candy
machine. Thus, the two possible operations are:
showSelection
: Show the number of products sold by the candy
machine.
makeSelection
: Allow the customer to select the product.
Search WWH ::
Custom Search