File tree Expand file tree Collapse file tree 3 files changed +38
-1
lines changed
lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank Expand file tree Collapse file tree 3 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,16 @@ public class BankAtm {
11
11
12
12
private final Map <UUID , Customer > customerById = new HashMap <>();
13
13
private final Map <String , CheckingAccount > accountByNumber = new HashMap <>();
14
+ public CheckingAccount createCheckingAccount (String accountNumber , Set <Customer > owners , double initialBalance ) {
15
+ boolean hasBusinessOwner = owners .stream ().anyMatch (Customer ::isBusiness );
14
16
17
+ if (hasBusinessOwner ) {
18
+ return new BusinessCheckingAccount (accountNumber , owners , initialBalance );
19
+ } else {
20
+ return new CheckingAccount (accountNumber , owners , initialBalance );
21
+ }
22
+ }
23
+
15
24
/**
16
25
* Adds a checking account to the bank.
17
26
*
Original file line number Diff line number Diff line change
1
+ package com .codedifferently .lesson17 .bank ;
2
+
3
+ import java .util .Set ;
4
+
5
+ public class BusinessCheckingAccount extends CheckingAccount {
6
+
7
+ public BusinessCheckingAccount (String accountNumber , Set <Customer > owners , double balance ) {
8
+ super (accountNumber , owners , balance );
9
+ validateBusinessOwners (owners );
10
+ }
11
+
12
+ private void validateBusinessOwners (Set <Customer > owners ) {
13
+ boolean hasBusinessOwner = owners .stream ().anyMatch (Customer ::isBusiness );
14
+ if (!hasBusinessOwner ) {
15
+ throw new IllegalArgumentException ("At least one owner must be a business for a BusinessCheckingAccount" );
16
+ }
17
+ }
18
+
19
+
20
+ }
Original file line number Diff line number Diff line change @@ -10,16 +10,20 @@ public class Customer {
10
10
private final UUID id ;
11
11
private final String name ;
12
12
private final Set <CheckingAccount > accounts = new HashSet <>();
13
+ private boolean isBusiness ;
14
+
13
15
14
16
/**
15
17
* Creates a new customer.
16
18
*
17
19
* @param id The ID of the customer.
18
20
* @param name The name of the customer.
19
21
*/
20
- public Customer (UUID id , String name ) {
22
+ public Customer (UUID id , String name , boolean isBusiness ) {
21
23
this .id = id ;
22
24
this .name = name ;
25
+ this .isBusiness = isBusiness ;
26
+
23
27
}
24
28
25
29
/**
@@ -75,4 +79,8 @@ public boolean equals(Object obj) {
75
79
public String toString () {
76
80
return "Customer{" + "id=" + id + ", name='" + name + '\'' + '}' ;
77
81
}
82
+
83
+ public boolean isBusiness () {
84
+ return isBusiness ;
85
+ }
78
86
}
You can’t perform that action at this time.
0 commit comments