M.8. Class BankDatabase

Class BankDatabase (Fig. M.7) models the bank’s database with which the ATM interacts to access and modify a user’s account information. We determine one reference-type attribute for class BankDatabase based on its composition relationship with class Account. Recall from Fig. 10.21 that a BankDatabase is composed of zero or more objects of class Account. Line 6 implements attribute accounts—an array of Account objects—to implement this composition relationship. Class BankDatabase has a no-argument constructor (lines 9–14) that initializes accounts to contain a set of new Account objects. For the sake of testing the system, we declare accounts to hold just two array elements (line 11), which we instantiate as new Account ...

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.