-
Notifications
You must be signed in to change notification settings - Fork 23
Feat: adds audit logging and multi-currency support to BankAtm #533
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
4cfaa8a
Feat: tiktok content creator system
kksaunders251 732e93e
Merge branch 'main' of https://github.com/kksaunders251/code-differen…
kksaunders251 581c616
Feat: adds the currency convertor and audit log
kksaunders251 97da979
feat: enhance BankAtm with money order support and multi-currency dep…
kksaunders251 6955ac9
feat: updating unit tests
kksaunders251 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
22 changes: 22 additions & 0 deletions
22
lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank/AuditLog.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,22 @@ | ||
package com.codedifferently.lesson17.bank; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class AuditLog { | ||
|
||
private final List<String> entries = new ArrayList<>(); | ||
|
||
public void record(String message) { | ||
entries.add(LocalDateTime.now() + " - " + message); | ||
} | ||
|
||
public List<String> getEntries() { | ||
return entries; | ||
} | ||
|
||
public void printLog() { | ||
entries.forEach(System.out::println); | ||
} | ||
} |
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
5 changes: 5 additions & 0 deletions
5
...n_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank/CurrencyConverter.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,5 @@ | ||
package com.codedifferently.lesson17.bank; | ||
|
||
public interface CurrencyConverter { | ||
double convert(double amount, String fromCurrency, String toCurrency); | ||
} |
7 changes: 7 additions & 0 deletions
7
.../bank_app/src/main/java/com/codedifferently/lesson17/bank/CurrencyConverterException.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,7 @@ | ||
package com.codedifferently.lesson17.bank; | ||
|
||
public class CurrencyConverterException extends RuntimeException { | ||
public CurrencyConverterException(String fromCurrency, String toCurrency) { | ||
super("Unsupported conversion from " + fromCurrency + " to " + toCurrency); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank/MoneyOrder.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,24 @@ | ||
package com.codedifferently.lesson17.bank; | ||
|
||
public class MoneyOrder { | ||
private final double amount; | ||
private final String sourceAccountNumber; | ||
|
||
public MoneyOrder(CheckingAccount sourceAccount, double amount) { | ||
this.amount = amount; | ||
this.sourceAccountNumber = sourceAccount.getAccountNumber(); | ||
sourceAccount.withdraw(amount); // Withdraw immediately | ||
} | ||
|
||
public double getAmount() { | ||
return amount; | ||
} | ||
|
||
public String getSourceAccountNumber() { | ||
return sourceAccountNumber; | ||
} | ||
|
||
public void depositTo(CheckingAccount destinationAccount) { | ||
destinationAccount.deposit(amount); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ank/bank_app/src/main/java/com/codedifferently/lesson17/bank/SimpleCurrencyConverter.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,25 @@ | ||
package com.codedifferently.lesson17.bank; | ||
|
||
import java.util.Map; | ||
|
||
public class SimpleCurrencyConverter implements CurrencyConverter { | ||
private final Map<String, Double> exchangeRates; | ||
|
||
public SimpleCurrencyConverter(Map<String, Double> exchangeRates) { | ||
this.exchangeRates = exchangeRates; | ||
} | ||
|
||
@Override | ||
public double convert(double amount, String fromCurrency, String toCurrency) { | ||
if (fromCurrency.equals(toCurrency)) return amount; | ||
|
||
String key = fromCurrency + "_TO_" + toCurrency; | ||
Double rate = exchangeRates.get(key); | ||
|
||
if (rate == null) { | ||
throw new CurrencyConverterException(fromCurrency, toCurrency); | ||
} | ||
|
||
return amount * rate; | ||
} | ||
} |
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.
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.
A constructor doesn't exist without a class.