Skip to content

Commit 019b887

Browse files
committed
chore: file mods
1 parent 5968b01 commit 019b887

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@ public class BankAtm {
1111

1212
private final Map<UUID, Customer> customerById = new HashMap<>();
1313
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);
1416

17+
if (hasBusinessOwner) {
18+
return new BusinessCheckingAccount(accountNumber, owners, initialBalance);
19+
} else {
20+
return new CheckingAccount(accountNumber, owners, initialBalance);
21+
}
22+
}
23+
1524
/**
1625
* Adds a checking account to the bank.
1726
*
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@ public class Customer {
1010
private final UUID id;
1111
private final String name;
1212
private final Set<CheckingAccount> accounts = new HashSet<>();
13+
private boolean isBusiness;
14+
1315

1416
/**
1517
* Creates a new customer.
1618
*
1719
* @param id The ID of the customer.
1820
* @param name The name of the customer.
1921
*/
20-
public Customer(UUID id, String name) {
22+
public Customer(UUID id, String name, boolean isBusiness) {
2123
this.id = id;
2224
this.name = name;
25+
this.isBusiness = isBusiness;
26+
2327
}
2428

2529
/**
@@ -75,4 +79,8 @@ public boolean equals(Object obj) {
7579
public String toString() {
7680
return "Customer{" + "id=" + id + ", name='" + name + '\'' + '}';
7781
}
82+
83+
public boolean isBusiness() {
84+
return isBusiness;
85+
}
7886
}

0 commit comments

Comments
 (0)