File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,20 @@ public BusinessCheckingAccount(
17
17
super (accountNumber , owners , initialBalance );
18
18
}
19
19
20
+ /**
21
+ * Checks if at least one owner is a business.
22
+ *
23
+ * @param owners The owers of the account.
24
+ * @throws IllegalArgumentEception If no business owner is found.
25
+ */
26
+ private void validateBusinessOwner (Set <Customer > owners ) {
27
+ boolean hasBusinessOwner = owners .stream ().anyMatch (Customer ::isBusiness );
28
+ if (!hasBusinessOwner ) {
29
+ throw new IllegalArgumentException (
30
+ "Business Checking Account must have at least one business owner" );
31
+ }
32
+ }
33
+
20
34
@ Override
21
35
public String toString () {
22
36
return "BusinessCheckingAccount{"
Original file line number Diff line number Diff line change @@ -60,6 +60,15 @@ public Set<Account> getAccounts() {
60
60
return accounts ;
61
61
}
62
62
63
+ /**
64
+ * Checks if the owner is a business.
65
+ *
66
+ * @return True if the customer is a business, false otherwise.
67
+ */
68
+ public boolean isBusiness () {
69
+ return this .type == CustomerType .BUSINESS ;
70
+ }
71
+
63
72
@ Override
64
73
public int hashCode () {
65
74
return id .hashCode ();
You can’t perform that action at this time.
0 commit comments