Skip to content

Commit 16b8b45

Browse files
committed
Feat: Adds for lesson 17 method implementation/ new funtionality for various files
1 parent d46c282 commit 16b8b45

File tree

7 files changed

+80
-3
lines changed

7 files changed

+80
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void addAccount(CheckingAccount account) {
3333
* @param customerId The ID of the customer.
3434
* @return The unique set of accounts owned by the customer.
3535
*/
36-
public Set<CheckingAccount> findAccountsByCustomerId(UUID customerId) {
36+
public Set<CheckingAccount> findAccountsByCustomerId(UUID customerId, UUID businessId) {
3737
return customerById.containsKey(customerId)
3838
? customerById.get(customerId).getAccounts()
3939
: Set.of();

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
/** Represents a customer of the bank. */
88
public class Customer {
99

10+
public static <T> boolean isBusiness(T t) {
11+
throw new UnsupportedOperationException("Not supported yet.");
12+
}
13+
1014
private final UUID id;
1115
private final String name;
1216
private final Set<CheckingAccount> accounts = new HashSet<>();
@@ -58,6 +62,10 @@ public Set<CheckingAccount> getAccounts() {
5862
return accounts;
5963
}
6064

65+
public boolean isBusiness() {
66+
return false;
67+
}
68+
6169
@Override
6270
public int hashCode() {
6371
return id.hashCode();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.codedifferently.lesson17.bank.exceptions;
2+
3+
public class MoneyOrder {}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 SavingsAccount extends CheckingAccount {
8+
9+
// Constructor for SavingsAccount
10+
public SavingsAccount(String accountNumber, Set<Customer> owners, double initialBalance) {
11+
super(accountNumber, owners, initialBalance);
12+
}
13+
14+
// Define the NullCheck class that blocks a check from being withdrawn
15+
public class NullCheck {
16+
17+
private boolean isVoided;
18+
private String checkNumber;
19+
private double amount;
20+
private String account;
21+
22+
public void blockCheckWithdrawal(
23+
double amount, String account, String checkNumber, boolean isVoided) {
24+
this.isVoided = isVoided;
25+
this.checkNumber = checkNumber;
26+
this.amount = amount;
27+
this.account = account;
28+
29+
// Example logic for blocking check withdrawal
30+
if (isVoided) {
31+
// Simulate a system that logs or handles the voided check
32+
System.out.println("Check " + checkNumber + " for account " + account + " is voided.");
33+
} else {
34+
// Process the withdrawal logic (not implemented here)
35+
System.out.println("Withdrawal blocked for check " + checkNumber);
36+
}
37+
38+
if (this.amount > 0) {}
39+
}
40+
41+
// Getters for properties
42+
public boolean getisVoided() {
43+
return isVoided;
44+
}
45+
46+
public String getCheckNumber() {
47+
return checkNumber;
48+
}
49+
50+
public double getAmount() {
51+
return amount;
52+
}
53+
54+
public String getAccount() {
55+
return account;
56+
}
57+
}
58+
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,20 @@ class BankAtmTest {
1515
private BankAtm classUnderTest;
1616
private CheckingAccount account1;
1717
private CheckingAccount account2;
18+
private CheckingAccount account3;
1819
private Customer customer1;
1920
private Customer customer2;
21+
private Customer customer3;
2022

2123
@BeforeEach
2224
void setUp() {
2325
classUnderTest = new BankAtm();
2426
customer1 = new Customer(UUID.randomUUID(), "John Doe");
2527
customer2 = new Customer(UUID.randomUUID(), "Jane Smith");
28+
customer3 = new Customer(UUID.randomUUID(), "Jane Smith's Business");
2629
account1 = new CheckingAccount("123456789", Set.of(customer1), 100.0);
2730
account2 = new CheckingAccount("987654321", Set.of(customer1, customer2), 200.0);
31+
account3 = new CheckingAccount("123456777", Set.of(customer2), 40000);
2832
customer1.addAccount(account1);
2933
customer1.addAccount(account2);
3034
customer2.addAccount(account2);
@@ -43,14 +47,16 @@ void testAddAccount() {
4347
classUnderTest.addAccount(account3);
4448

4549
// Assert
46-
Set<CheckingAccount> accounts = classUnderTest.findAccountsByCustomerId(customer3.getId());
50+
Set<CheckingAccount> accounts =
51+
classUnderTest.findAccountsByCustomerId(customer3.getId(), null);
4752
assertThat(accounts).containsOnly(account3);
4853
}
4954

5055
@Test
5156
void testFindAccountsByCustomerId() {
5257
// Act
53-
Set<CheckingAccount> accounts = classUnderTest.findAccountsByCustomerId(customer1.getId());
58+
Set<CheckingAccount> accounts =
59+
classUnderTest.findAccountsByCustomerId(customer1.getId(), null);
5460

5561
// Assert
5662
assertThat(accounts).containsOnly(account1, account2);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)