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(
1717 super (accountNumber , owners , initialBalance );
1818 }
1919
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+
2034 @ Override
2135 public String toString () {
2236 return "BusinessCheckingAccount{"
Original file line number Diff line number Diff line change @@ -60,6 +60,15 @@ public Set<Account> getAccounts() {
6060 return accounts ;
6161 }
6262
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+
6372 @ Override
6473 public int hashCode () {
6574 return id .hashCode ();
You can’t perform that action at this time.
0 commit comments