Skip to content

Commit 71e7dd2

Browse files
author
AmiyahJo
committed
feat: adds boolean businessCheckingAccount in the method 'addAccount'
within BankAtm
1 parent bd2aab0 commit 71e7dd2

File tree

1 file changed

+10
-1
lines changed
  • lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank

1 file changed

+10
-1
lines changed

lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank/BankAtm.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,16 @@ public class BankAtm {
1919
*
2020
* @param account The account to add.
2121
*/
22-
public void addAccount(CheckingAccount account) {
22+
public void addAccount(CheckingAccount account) {
23+
if (account instanceof BusinessCheckingAccount) {
24+
boolean hasBusinessAccount = account.getOwners().stream()
25+
.anyMatch(owner -> owner.isBusiness());
26+
27+
if(!hasBusinessAccount) {
28+
throw new IllegalArgumentException("At least one owning account must be a business account.");
29+
}
30+
}
31+
2332
accountByNumber.put(account.getAccountNumber(), account);
2433
account
2534
.getOwners()

0 commit comments

Comments
 (0)