-
Notifications
You must be signed in to change notification settings - Fork 23
feat: implements SavingsAccount & BusinessCheckingAccount class #523
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 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0e0ec62
feat: adds Account superclass for CheckingAccount
a28e5c8
Merge branch 'code-differently:main' into feat/lesson_17
TatsuyaRyujin 1f7acc3
feat: immplements SavingsAccount class
8d69a4e
refactor: ran spotlessApply
04be46f
feat: adds BusinessCheckingAccount class
a6f21fa
feat: adds SavingsAccount Tests
TatsuyaRyujin 4de921f
Merge branch 'code-differently:main' into feat/lesson_17
TatsuyaRyujin 7d5637e
adds validateBusinessOwners method
TatsuyaRyujin 9e38276
adds BusinessCheckingAccount Tests
TatsuyaRyujin 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
94 changes: 94 additions & 0 deletions
94
lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank/Account.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,94 @@ | ||
package com.codedifferently.lesson17.bank; | ||
|
||
import com.codedifferently.lesson17.bank.exceptions.InsufficientFundsException; | ||
import java.util.Set; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
/** Abstract base class for all bank accounts. */ | ||
@Getter | ||
@Setter | ||
public abstract class Account { | ||
private final Set<Customer> owners; | ||
private final String accountNumber; | ||
private double balance; | ||
private boolean isActive; | ||
|
||
/** | ||
* Creates a new account. | ||
* | ||
* @param accountNumber The account number. | ||
* @param owners The owners of the account. | ||
* @param initalBalance The inital balance of the account. | ||
*/ | ||
public Account(String accountNumber, Set<Customer> owners, double initalBalance) { | ||
this.accountNumber = accountNumber; | ||
this.owners = owners; | ||
this.balance = initalBalance; | ||
this.isActive = true; | ||
} | ||
|
||
/** | ||
* Deposits funds into the account. | ||
* | ||
* @param amount The amount to deposit. | ||
*/ | ||
public void deposit(double amount) throws IllegalStateException { | ||
if (isClosed()) { | ||
throw new IllegalStateException("Cannot deposit to a closed account"); | ||
} | ||
if (amount <= 0) { | ||
throw new IllegalArgumentException("Deposit amount must be positive"); | ||
} | ||
balance += amount; | ||
} | ||
|
||
/** | ||
* Withdraws funds from the account. | ||
* | ||
* @param amount | ||
* @throws InsufficientFundsException | ||
*/ | ||
public void withdraw(double amount) throws InsufficientFundsException { | ||
if (isClosed()) { | ||
throw new IllegalStateException("Cannot withdraw from a closed account"); | ||
} | ||
if (amount <= 0) { | ||
throw new IllegalStateException("Withdrawal amount must be positive"); | ||
} | ||
if (balance < amount) { | ||
throw new InsufficientFundsException("Account does not have enough funds for withdrawal"); | ||
} | ||
balance -= amount; | ||
} | ||
|
||
/** Closes the account. */ | ||
public void closeAccount() throws IllegalStateException { | ||
if (balance > 0) { | ||
throw new IllegalStateException("Cannot close account with a positive balance"); | ||
} | ||
isActive = false; | ||
} | ||
|
||
/** | ||
* Checks if the account is closed. | ||
* | ||
* @return True if the account is closed, otherwise false. | ||
*/ | ||
public boolean isClosed() { | ||
return !isActive; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return accountNumber.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj instanceof CheckingAccount other) { | ||
return accountNumber.equals(other.getAccountNumber()); | ||
} | ||
return false; | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.