M.5. Class CashDispenser

Class CashDispenser (Fig. M.4) represents the cash dispenser of the ATM. Line 7 declares constant INITIAL_COUNT, which indicates the initial count of bills in the cash dispenser when the ATM starts (i.e., 500). Line 8 implements attribute count (modeled in Fig. 10.22), which keeps track of the number of bills remaining in the CashDispenser at any time. The constructor (lines 11–14) sets count to the initial count. Class CashDispenser has two public methods—dispenseCash (lines 17–21) and isSufficientCashAvailable (lines 24–32). The class trusts that a client (i.e., Withdrawal) calls dispenseCash only after establishing that sufficient cash is available by calling isSufficientCashAvailable. Thus, dispenseCash simply simulates ...

Get Java™ How to Program, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.