javahashmapumlbank

Java Bank based on a UML Class Diagram; trouble with the HashMap storage


enter image description here

Hello, so i have to implement a Bank management software based on this UML. Alright, since between Person and Bank there's composition, and the same goes with Account and Bank, i've decided to store all the data like this:

Hashmap <Person, ArrayList<Account>>

To each Person i can have a list of open Accounts(Spending or Saving) and i will access these fields from the Bank class(where I have add/remove Person, add/remove Account, deposit(Person,Account), withdraw(Person,Account)).

My question is the following: how do I add an account to the bank's HashMap, in the ArrayList pointed at by Person p?


Solution

  •  Hashmap<Person, ArrayList<Account>> bankAccounts = new Hashmap<Person, ArrayList<Account>>();
    
     Person person = new Person("Rares"); // considering you can create a person with just a name field for example
    
     bankAccounts.get(person).add(new Account());