File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 1
1
package com .codedifferently .lesson17 .bank ;
2
2
3
- import com .codedifferently .lesson17 .bank .exceptions .AccountNotFoundException ;
4
3
import java .util .HashMap ;
5
4
import java .util .Map ;
6
5
import java .util .Set ;
7
6
import java .util .UUID ;
8
7
8
+ import com .codedifferently .lesson17 .bank .exceptions .AccountNotFoundException ;
9
+
9
10
/** Represents a bank ATM. */
10
11
public class BankAtm {
11
12
@@ -18,6 +19,20 @@ public class BankAtm {
18
19
* @param account The account to add.
19
20
*/
20
21
public void addAccount (CheckingAccount account ) {
22
+ if (account instanceof BusinessCheckingAccount ) {
23
+ boolean hasBusinessAccount = false ;
24
+ for (Customer owner : account .getOwners ()) {
25
+ Customer customer = customerById .get (owner .getId ());
26
+ if (customer != null && customer .hasBusinessAccount ()) {
27
+ hasBusinessAccount = true ;
28
+ break ;
29
+ }
30
+ }
31
+ if (!hasBusinessAccount ) {
32
+ throw new IllegalArgumentException ("At least one owning account must be a business account." );
33
+ }
34
+ }
35
+
21
36
accountByNumber .put (account .getAccountNumber (), account );
22
37
account
23
38
.getOwners ()
@@ -27,6 +42,7 @@ public void addAccount(CheckingAccount account) {
27
42
});
28
43
}
29
44
45
+
30
46
/**
31
47
* Finds all accounts owned by a customer.
32
48
*
Original file line number Diff line number Diff line change @@ -58,6 +58,20 @@ public Set<CheckingAccount> getAccounts() {
58
58
return accounts ;
59
59
}
60
60
61
+ /**
62
+ * Checks if the customer has at least one business account.
63
+ *
64
+ * @return true if the customer has a business account, false otherwise.
65
+ */
66
+ public boolean hasBusinessAccount () {
67
+ for (CheckingAccount account : accounts ) {
68
+ if (account instanceof BusinessCheckingAccount ) {
69
+ return true ; // Found a business account
70
+ }
71
+ }
72
+ return false ;
73
+ }
74
+
61
75
@ Override
62
76
public int hashCode () {
63
77
return id .hashCode ();
You can’t perform that action at this time.
0 commit comments