Skip to content

Commit 35d6838

Browse files
committed
feat: adds Business checking account for lesson 17
1 parent 4b73af3 commit 35d6838

File tree

11 files changed

+123
-12
lines changed

11 files changed

+123
-12
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
package com.codedifferently.lesson17;
22

3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import java.util.Set;
6+
import java.util.UUID;
7+
8+
9+
10+
//* Represents a Savings account */
311
public class SavingsAccount {
412

513
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.codedifferently.lesson17.bank;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import java.util.Set;
6+
import java.util.UUID;
7+
8+
import org.apache.logging.log4j.LogManager;
9+
import org.apache.logging.log4j.Logger;
10+
11+
//* Represents an Audit log. */
12+
public class AuditLog {
13+
14+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package com.codedifferently.lesson17.bank;
22

3-
import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException;
43
import java.util.HashMap;
54
import java.util.Map;
65
import java.util.Set;
76
import java.util.UUID;
87

8+
import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException;
9+
910
/** Represents a bank ATM. */
1011
public class BankAtm {
1112

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.codedifferently.lesson17.bank;
2+
3+
import java.util.Set;
4+
5+
public class BusinessChecking extends CheckingAccount {
6+
//By extending the checking account class it will call to the methods of the
7+
8+
public BusinessChecking(String accountNumber, Set<Customer> owners, double initialBalance) {
9+
super(accountNumber, owners, initialBalance);
10+
11+
boolean hasBusinessOwner = false;
12+
for (Customer owner : owners) {
13+
if (owner.isBusiness()) {
14+
hasBusinessOwner = true;
15+
break;
16+
}
17+
}
18+
19+
if (!hasBusinessOwner) {
20+
throw new IllegalArgumentException("Business account must have at least one business owner.");
21+
}
22+
}
23+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.codedifferently.lesson17.bank;
2+
3+
public enum BusinessCheckingAccount {
4+
5+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package com.codedifferently.lesson17.bank;
22

3-
import com.codedifferently.lesson17.bank.exceptions.InsufficientFundsException;
43
import java.util.Set;
54

5+
import com.codedifferently.lesson17.bank.exceptions.InsufficientFundsException;
6+
67
/** Represents a checking account. */
78
public class CheckingAccount {
89

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

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

1415
/**
1516
* Creates a new customer.
1617
*
1718
* @param id The ID of the customer.
1819
* @param name The name of the customer.
1920
*/
20-
public Customer(UUID id, String name) {
21+
public Customer(UUID id, String name, boolean isBusiness) {
2122
this.id = id;
2223
this.name = name;
24+
this.isBusiness = isBusiness;
2325
}
2426

2527
/**
@@ -75,4 +77,8 @@ public boolean equals(Object obj) {
7577
public String toString() {
7678
return "Customer{" + "id=" + id + ", name='" + name + '\'' + '}';
7779
}
80+
81+
public boolean isBusiness() {
82+
return isBusiness;
83+
}
7884
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3+
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
4+
*/
5+
6+
package com.codedifferently.lesson17.bank;
7+
8+
9+
class account {
10+
11+
static Object getOwners() {
12+
throw new UnsupportedOperationException("Not supported yet.");
13+
}
14+
15+
}

lesson_17/bank/bank_app/src/test/java/com/codedifferently/lesson17/bank/BankAtmTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package com.codedifferently.lesson17.bank;
22

3+
import java.util.Set;
4+
import java.util.UUID;
5+
36
import static org.assertj.core.api.Assertions.assertThat;
47
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
8+
import org.junit.jupiter.api.BeforeEach;
9+
import org.junit.jupiter.api.Test;
510

611
import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException;
712
import com.codedifferently.lesson17.bank.exceptions.CheckVoidedException;
8-
import java.util.Set;
9-
import java.util.UUID;
10-
import org.junit.jupiter.api.BeforeEach;
11-
import org.junit.jupiter.api.Test;
1213

1314
class BankAtmTest {
1415

@@ -21,8 +22,8 @@ class BankAtmTest {
2122
@BeforeEach
2223
void setUp() {
2324
classUnderTest = new BankAtm();
24-
customer1 = new Customer(UUID.randomUUID(), "John Doe");
25-
customer2 = new Customer(UUID.randomUUID(), "Jane Smith");
25+
customer1 = new Customer(UUID.randomUUID(), "John Doe", false);
26+
customer2 = new Customer(UUID.randomUUID(), "Jane Smith", false);
2627
account1 = new CheckingAccount("123456789", Set.of(customer1), 100.0);
2728
account2 = new CheckingAccount("987654321", Set.of(customer1, customer2), 200.0);
2829
customer1.addAccount(account1);
@@ -35,7 +36,7 @@ void setUp() {
3536
@Test
3637
void testAddAccount() {
3738
// Arrange
38-
Customer customer3 = new Customer(UUID.randomUUID(), "Alice Johnson");
39+
Customer customer3 = new Customer(UUID.randomUUID(), "Alice Johnson", false);
3940
CheckingAccount account3 = new CheckingAccount("555555555", Set.of(customer3), 300.0);
4041
customer3.addAccount(account3);
4142

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.codedifferently.lesson17.bank;
2+
3+
import java.util.Set;
4+
import java.util.UUID;
5+
6+
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
import static org.junit.jupiter.api.Assertions.assertThrows;
8+
import org.junit.jupiter.api.Test;
9+
10+
public class BusinessCheckingAccountTest {
11+
12+
13+
public class BusinessCheckingTest {
14+
15+
@Test
16+
public void testValidBusinessCheckingAccount() {
17+
Customer bob = new Customer(UUID.randomUUID(), "Bob", true); // is a business
18+
Set<Customer> owners = Set.of(bob);
19+
20+
BusinessChecking account = new BusinessChecking("BUS-001", owners, 100.0);
21+
assertEquals("BUS-001", account.getAccountNumber());
22+
}
23+
24+
@Test
25+
public void testInvalidBusinessCheckingAccountThrowsException() {
26+
Customer alice = new Customer(UUID.randomUUID(), "Alice", false); // personal
27+
Set<Customer> owners = Set.of(alice);
28+
29+
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
30+
new BusinessChecking("BUS-002", owners, 100.0);
31+
});
32+
33+
assertEquals("Business account must have at least one business owner.", exception.getMessage());
34+
}
35+
}
36+
37+
}

0 commit comments

Comments
 (0)