Skip to content

Commit c0f481d

Browse files
committed
feat: Dasia's Lesson_17 Business Checking Account and Savings Account
1 parent 639a49f commit c0f481d

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class Customer {
1010
private final UUID id;
1111
private final String name;
1212
private final Set<CheckingAccount> accounts = new HashSet<>();
13+
private boolean hasBusinessOwner;
1314

1415
/**
1516
* Creates a new customer.
@@ -20,6 +21,7 @@ public class Customer {
2021
public Customer(UUID id, String name) {
2122
this.id = id;
2223
this.name = name;
24+
this.hasBusinessOwner = false;
2325
}
2426

2527
/**
@@ -71,6 +73,18 @@ public boolean equals(Object obj) {
7173
return false;
7274
}
7375

76+
public void changeToBusinessAccount() {
77+
hasBusinessOwner = true;
78+
}
79+
80+
public boolean hasBusinessOwner() {
81+
return false;
82+
}
83+
84+
public boolean getHasBusinessOwner() {
85+
return true;
86+
}
87+
7488
@Override
7589
public String toString() {
7690
return "Customer{" + "id=" + id + ", name='" + name + '\'' + '}';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.codedifferently.lesson17.bank.exceptions;
2+
3+
import com.codedifferently.lesson17.bank.CheckingAccount;
4+
import com.codedifferently.lesson17.bank.Customer;
5+
import java.util.Set;
6+
7+
public class BusinessCheckingAccount extends CheckingAccount {
8+
public BusinessCheckingAccount(
9+
String accountNumber, Set<Customer> owners, double initialBalance) {
10+
super(accountNumber, owners, initialBalance);
11+
if (!hasBusinessOwner(owners)) {
12+
throw new IllegalArgumentException(
13+
"A business account requires at least one owner to be a business.");
14+
}
15+
}
16+
17+
private boolean hasBusinessOwner(Set<Customer> owners) {
18+
return owners.stream()
19+
.anyMatch(
20+
owner ->
21+
owner.getName().toUpperCase().contains("INC")
22+
|| owner.getName().toUpperCase().contains("LLC")
23+
|| owner.getName().toUpperCase().contains("CO."));
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.codedifferently.lesson17.bank;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertNotNull;
5+
6+
import com.codedifferently.lesson17.bank.exceptions.BusinessCheckingAccount;
7+
import java.util.HashSet;
8+
import java.util.Set;
9+
import java.util.UUID;
10+
import org.junit.jupiter.api.BeforeEach;
11+
import org.junit.jupiter.api.Test;
12+
13+
public class BusinessCheckingAccountTest {
14+
private BusinessCheckingAccount classUnderTest;
15+
private Set<Customer> owners;
16+
17+
@BeforeEach
18+
void setUp() {
19+
owners = new HashSet<>();
20+
}
21+
22+
@Test
23+
void testHasBusinessOwner_withINCInTheName() {
24+
UUID id = UUID.randomUUID();
25+
Customer businessOwner = new Customer(id, "Company INC");
26+
owners.add(businessOwner);
27+
28+
BusinessCheckingAccount account = new BusinessCheckingAccount("123456", owners, 200);
29+
assertNotNull(account);
30+
assertEquals("123456", account.getAccountNumber());
31+
assertEquals(200, account.getBalance());
32+
}
33+
34+
@Test
35+
void testHasBusinessOwner_withLLCInTheName() {
36+
UUID id = UUID.randomUUID();
37+
Customer businessOwner = new Customer(id, "Company ILLC");
38+
owners.add(businessOwner);
39+
40+
BusinessCheckingAccount account = new BusinessCheckingAccount("123456", owners, 200);
41+
assertNotNull(account);
42+
assertEquals("123456", account.getAccountNumber());
43+
assertEquals(200, account.getBalance());
44+
}
45+
46+
@Test
47+
void testHasBusinessOwner_withCOInTheName() {
48+
UUID id = UUID.randomUUID();
49+
Customer businessOwner = new Customer(id, "Company CO.");
50+
owners.add(businessOwner);
51+
52+
BusinessCheckingAccount account = new BusinessCheckingAccount("123456", owners, 200);
53+
assertNotNull(account);
54+
assertEquals("123456", account.getAccountNumber());
55+
assertEquals(200, account.getBalance());
56+
}
57+
}

0 commit comments

Comments
 (0)