Skip to content

Commit 34b6dd3

Browse files
committed
feat:lesson_17 added additional files
1 parent d46c282 commit 34b6dd3

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.codedifferently.lesson17.bank;
2+
3+
import java.util.Set;
4+
5+
public class BusinessCheckingAccount extends CheckingAccount {
6+
public BusinessCheckingAccount(String accountNumber, Set<Customer> owners, double balance) {
7+
super(accountNumber, owners, balance);
8+
if (!hasBusinessOwner(owners)) {
9+
throw new IllegalArgumentException("requires at least one business owner.");
10+
}
11+
}
12+
13+
private boolean hasBusinessOwner(Set<Customer> owners) {
14+
return owners.stream().anyMatch(Customer::isBusiness);
15+
}
16+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.codedifferently.lesson17.bank;
2+
3+
import java.util.UUID;
4+
5+
public class BusinessOwner extends Customer {
6+
7+
private final String businessName;
8+
9+
public BusinessOwner(UUID id, String name, String businessName) {
10+
super(id, name);
11+
this.businessName = businessName;
12+
}
13+
14+
public String businessName() {
15+
return businessName;
16+
}
17+
18+
@Override
19+
public boolean isBusiness() {
20+
return true;
21+
}
22+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public Check(String checkNumber, double amount, CheckingAccount account) {
2121
if (amount < 0) {
2222
throw new IllegalArgumentException("Check amount must be positive");
2323
}
24+
if (account instanceof SavingsAccount) {
25+
throw new UnsupportedOperationException("Cannot issue checks from a savings account.");
26+
}
2427
this.checkNumber = checkNumber;
2528
this.amount = amount;
2629
this.account = account;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public Set<CheckingAccount> getAccounts() {
5858
return accounts;
5959
}
6060

61+
// defaults accounts to non-business Owners.
62+
public boolean isBusiness() {
63+
return false;
64+
}
65+
6166
@Override
6267
public int hashCode() {
6368
return id.hashCode();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.codedifferently.lesson17.bank;
2+
3+
import java.util.Set;
4+
5+
// represents a savings account
6+
public class SavingsAccount extends CheckingAccount {
7+
8+
public SavingsAccount(String accountNumber, Set<Customer> owners, double balance) {
9+
super(accountNumber, owners, balance);
10+
}
11+
}

0 commit comments

Comments
 (0)