-
Notifications
You must be signed in to change notification settings - Fork 25
feat: implemented SavingsAccount and BusinessCheckingAccount classes #551
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7f1e94f
feat: Initial commit of Lesson 17. Still WIP.
marleomac3 57e1ded
Merge branch 'code-differently:main' into lj-lesson-17
marleomac3 22fd2a9
feat: implemented savings account class and modified test and related…
marleomac3 b4b886b
feat: modified Javadocs for Check and BankAtm classes
marleomac3 c946252
fix: ran gradlew command to fix violation
marleomac3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...ank/bank_app/src/main/java/com/codedifferently/lesson17/bank/BusinessCheckingAccount.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.codedifferently.lesson17.bank; | ||
|
||
import java.util.Set; | ||
|
||
public class BusinessCheckingAccount extends CheckingAccount { | ||
|
||
/** | ||
* Creates a new BusinessCheckingAccount with the specified account number, owners, and initial | ||
* balance. | ||
* | ||
* <p>This constructor ensures that the account meets the minimum requirements for a business | ||
* checking account, including a minimum initial balance of $10,000 and at least one business | ||
* owner in the provided set of owners. If these requirements are not met, an {@link | ||
* IllegalArgumentException} is thrown. | ||
* | ||
* @param accountNumber The unique identifier for the account. | ||
* @param owners A set of {@link Customer} objects representing the owners of the account. | ||
* @param initialBalance The initial balance of the account, which must be at least $10,000. | ||
* @throws IllegalArgumentException If the initial balance is less than $10,000 or if none of the | ||
* owners meet the criteria to be considered a business owner. | ||
*/ | ||
public BusinessCheckingAccount( | ||
String accountNumber, Set<Customer> owners, double initialBalance) { | ||
super(accountNumber, owners, initialBalance); | ||
|
||
// Business Account Logic | ||
if (initialBalance < 10000) { | ||
throw new IllegalArgumentException("Business accounts require a minimum balance of $10,000."); | ||
} | ||
if (!hasBusinessOwner(owners)) { | ||
throw new IllegalArgumentException( | ||
"A business checking account must have at least one business owner."); | ||
} | ||
} | ||
|
||
/** | ||
* Checks if at least one owner of the account is a business. | ||
* | ||
* <p>This method examines each owner in the "owners" set and returns true if any owner's name | ||
* contains "INC" or "LLC" (case-insensitive), which are used as indicators of a business owning | ||
* the account. | ||
* | ||
* @param owners The set of account owners to check. | ||
* @return true if the account has at least one business owner; false otherwise. | ||
*/ | ||
public boolean hasBusinessOwner(Set<Customer> owners) { | ||
return getOwners().stream() | ||
.anyMatch( | ||
owner -> | ||
owner.getName().toUpperCase().contains("INC") | ||
|| owner.getName().toUpperCase().contains("LLC")); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank/SavingsAccount.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.codedifferently.lesson17.bank; | ||
|
||
import java.util.Set; | ||
|
||
public class SavingsAccount extends CheckingAccount { | ||
|
||
public SavingsAccount(String accountNumber, Set<Customer> owners, double initialBalance) { | ||
super(accountNumber, owners, initialBalance); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...bank_app/src/test/java/com/codedifferently/lesson17/bank/BusinessCheckingAccountTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.codedifferently.lesson17.bank; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class BusinessCheckingAccountTest { | ||
private Set<Customer> owners; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
owners = new HashSet<>(); | ||
} | ||
|
||
@Test | ||
public void testBusinessCheckingAccount_HasBusinessOwner_WithIncInName() { | ||
UUID id = UUID.randomUUID(); | ||
Customer businesserOwner = new Customer(id, "Bob INC."); | ||
|
||
owners.add(businesserOwner); | ||
|
||
BusinessCheckingAccount account = new BusinessCheckingAccount("12345", owners, 15000); | ||
assertNotNull(account); | ||
assertEquals(15000, account.getBalance()); | ||
assertEquals("12345", account.getAccountNumber()); | ||
} | ||
|
||
@Test | ||
public void testBusinessCheckingAccount_HasBusinessOwner_WithLlcInName() { | ||
UUID id = UUID.randomUUID(); | ||
Customer businesserOwner = new Customer(id, "Bob LLC."); | ||
|
||
owners.add(businesserOwner); | ||
|
||
BusinessCheckingAccount account = new BusinessCheckingAccount("12345", owners, 15000); | ||
assertNotNull(account); | ||
assertEquals(15000, account.getBalance()); | ||
assertEquals("12345", account.getAccountNumber()); | ||
} | ||
|
||
@Test | ||
public void testBusinessCheckingAccount_WithoutBusinessOwner() { | ||
UUID individualId = UUID.randomUUID(); | ||
Customer individualOwner = | ||
new Customer(individualId, "John Doe"); // Example customer without business designation | ||
|
||
owners.add(individualOwner); // Add the individual owner to the set | ||
|
||
assertThatThrownBy( | ||
() -> { | ||
new BusinessCheckingAccount("12345", owners, 15000); | ||
}) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessageContaining("A business checking account must have at least one business owner."); | ||
} | ||
|
||
@Test | ||
public void testBusinessCheckingAccount_BelowMinimumBalance() { | ||
UUID businessId = UUID.randomUUID(); | ||
Customer businessOwner = | ||
new Customer(businessId, "ABC LLC"); // Create a customer with a valid business name | ||
|
||
owners.add(businessOwner); // Add the business owner to the set | ||
|
||
assertThatThrownBy( | ||
() -> { | ||
new BusinessCheckingAccount( | ||
"12345", owners, 5000); // Attempt to create with a balance below 10,000 | ||
}) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessageContaining("Business accounts require a minimum balance of $10,000."); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
..._17/bank/bank_app/src/test/java/com/codedifferently/lesson17/bank/SavingsAccountTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.codedifferently.lesson17.bank; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
||
public class SavingsAccountTest { | ||
private SavingsAccount savingsAccount; | ||
private Set<Customer> owners; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
owners = new HashSet<>(); | ||
owners.add(new Customer(UUID.randomUUID(), "Bob Smith")); | ||
savingsAccount = new SavingsAccount("12345", owners, 500); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you add this? This was not in the requirements.