Skip to content

Commit 581c616

Browse files
committed
Feat: adds the currency convertor and audit log
1 parent 732e93e commit 581c616

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.codedifferently.lesson17.bank;
2+
3+
public class AuditLog {
4+
private final List<String> entries = new ArrayList<>();
5+
6+
public void record(String message) {
7+
entries.add(LocalDateTime.now() + " - " + message);
8+
}
9+
10+
public List<String> getEntries() {
11+
return entries;
12+
}
13+
}
14+
15+

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
package com.codedifferently.lesson17.bank;
22

3-
import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException;
43
import java.util.HashMap;
54
import java.util.Map;
65
import java.util.Set;
76
import java.util.UUID;
87

8+
import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException;
9+
910
/** Represents a bank ATM. */
1011
public class BankAtm {
1112

13+
1214
private final Map<UUID, Customer> customerById = new HashMap<>();
1315
private final Map<String, CheckingAccount> accountByNumber = new HashMap<>();
16+
private final AuditLog auditLog();
17+
private final CurrencyConverter currencyConverter();
18+
19+
public BankAtm(AuditLog auditLog, CurrencyConverter currencyConverter){
1420

21+
this.auditLog() = auditLog;
22+
this.currencyConverter() = currencyConverter;
23+
}
24+
25+
26+
27+
}
1528
/**
1629
* Adds a checking account to the bank.
1730
*
@@ -85,4 +98,4 @@ private CheckingAccount getAccountOrThrow(String accountNumber) {
8598
}
8699
return account;
87100
}
88-
}
101+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.codedifferently.lesson17.bank;
2+
3+
public class CurrencyConverter {
4+
private final Map<Currency, Double> exchangeRates;
5+
6+
public CurrencyConverter() {
7+
exchangeRates = new HashMap<>();
8+
exchangeRates.put(Currency.USD, 1.0);
9+
exchangeRates.put(Currency.EUR, 1.1);
10+
exchangeRates.put(Currency.GBP, 1.3);
11+
12+
}
13+
14+
public double convert(double amount, Currency from, Currency to) {
15+
double usd = amount / exchangeRates.get(from);
16+
return usd * exchangeRates.get(to);
17+
}
18+
}

0 commit comments

Comments
 (0)