Skip to content

feat:adds Savings Account file for lesson 17 #529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ private CheckingAccount getAccountOrThrow(String accountNumber) {
}
return account;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.codedifferently.lesson17.bank;

import java.util.Set;

public class BusinessChecking extends CheckingAccount {
// By extending the checking account class it will call to the methods of the checking account.

public BusinessChecking(String accountNumber, Set<Customer> owners, double initialBalance) {
super(accountNumber, owners, initialBalance);

boolean hasBusinessOwner =
false; // Have a for loop for to detect if the customer is a business owner//
for (Customer owner : owners) {
if (owner.isBusiness()) {
hasBusinessOwner = true;
break;
}
}

if (!hasBusinessOwner) { // If that customer is not a business owner, it will throw an
// exception//
throw new IllegalArgumentException("Business account must have at least one business owner.");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.codedifferently.lesson17.bank;

import com.codedifferently.lesson17.bank.exceptions.InsufficientFundsException;
import java.util.Set;

import com.codedifferently.lesson17.bank.exceptions.InsufficientFundsException;

/** Represents a checking account. */
public class CheckingAccount {

Expand Down Expand Up @@ -128,4 +129,4 @@ public String toString() {
+ isActive
+ '}';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ public class Customer {
private final UUID id;
private final String name;
private final Set<CheckingAccount> accounts = new HashSet<>();
private final boolean isBusiness;

/**
* Creates a new customer.
*
* @param id The ID of the customer.
* @param name The name of the customer.
*/
public Customer(UUID id, String name) {
public Customer(UUID id, String name, boolean isBusiness) {
this.id = id;
this.name = name;
this.isBusiness = isBusiness;
}

/**
Expand Down Expand Up @@ -75,4 +77,8 @@ public boolean equals(Object obj) {
public String toString() {
return "Customer{" + "id=" + id + ", name='" + name + '\'' + '}';
}

public boolean isBusiness() {
return isBusiness;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.codedifferently.lesson17.bank;

public class SavingsAccount {


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/

package com.codedifferently.lesson17.bank;

class account {
public static void main(String[] args) {
static Object getOwners() {
return "Owner information not available.";
}
static Object ›() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class BankAtmTest {
@BeforeEach
void setUp() {
classUnderTest = new BankAtm();
customer1 = new Customer(UUID.randomUUID(), "John Doe");
customer2 = new Customer(UUID.randomUUID(), "Jane Smith");
customer1 = new Customer(UUID.randomUUID(), "John Doe", false);
customer2 = new Customer(UUID.randomUUID(), "Jane Smith", false);
account1 = new CheckingAccount("123456789", Set.of(customer1), 100.0);
account2 = new CheckingAccount("987654321", Set.of(customer1, customer2), 200.0);
customer1.addAccount(account1);
Expand All @@ -35,7 +35,7 @@ void setUp() {
@Test
void testAddAccount() {
// Arrange
Customer customer3 = new Customer(UUID.randomUUID(), "Alice Johnson");
Customer customer3 = new Customer(UUID.randomUUID(), "Alice Johnson", false);
CheckingAccount account3 = new CheckingAccount("555555555", Set.of(customer3), 300.0);
customer3.addAccount(account3);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.codedifferently.lesson17.bank;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.Set;
import java.util.UUID;
import org.junit.jupiter.api.Test;

public class BusinessCheckingAccountTest {

public class BusinessCheckingTest {

@Test
public void testValidBusinessCheckingAccount() {
Customer bob = new Customer(UUID.randomUUID(), "Bob", true); // is a business
Set<Customer> owners = Set.of(bob);

BusinessChecking account = new BusinessChecking("BUS-001", owners, 100.0);
assertEquals("BUS-001", account.getAccountNumber());
}

@Test
public void testInvalidBusinessCheckingAccountThrowsException() {
Customer alice = new Customer(UUID.randomUUID(), "Alice", false); // personal
Set<Customer> owners = Set.of(alice);

Exception exception =
assertThrows(
IllegalArgumentException.class,
() -> {
new BusinessChecking("BUS-002", owners, 100.0);
});

assertEquals(
"Business account must have at least one business owner.", exception.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class CheckingAccountTest {
@BeforeEach
void setUp() {
owners = new HashSet<>();
owners.add(new Customer(UUID.randomUUID(), "John Doe"));
owners.add(new Customer(UUID.randomUUID(), "Jane Smith"));
owners.add(new Customer(UUID.randomUUID(), "John Doe", false));
owners.add(new Customer(UUID.randomUUID(), "Jane Smith", false));
classUnderTest = new CheckingAccount("123456789", owners, 100.0);
}

Expand Down
Loading