11package com .codedifferently .lesson17 .bank ;
22
3- import com .codedifferently .lesson17 .bank .exceptions .AccountNotFoundException ;
43import java .util .HashMap ;
54import java .util .Map ;
65import java .util .Set ;
76import java .util .UUID ;
87
9- /** Represents a bank ATM. */
8+ import com .codedifferently .lesson17 .bank .exceptions .AccountNotFoundException ;
9+
10+ /**
11+ * Represents a bank ATM system that manages customer accounts and transactions.
12+ *
13+ * <p>This ATM supports various types of checking accounts including standard
14+ * {@link CheckingAccount} and specialized {@link BusinessCheckingAccount} instances.
15+ * The system uses polymorphism to treat all account types uniformly, enabling
16+ * seamless operations regardless of the specific account implementation.
17+ *
18+ * <p>Supported operations include:
19+ * <ul>
20+ * <li>Adding accounts to the system</li>
21+ * <li>Finding accounts by customer ID</li>
22+ * <li>Depositing funds (cash or check) with multi-currency support</li>
23+ * <li>Withdrawing funds</li>
24+ * </ul>
25+ *
26+ * <p>The ATM supports deposits in multiple currencies including USD, EUR, GBP, JPY,
27+ * CAD, AUD, CHF, and CNY. All currency conversions are handled automatically using
28+ * the integrated {@link CurrencyConverter}, with all account balances maintained in USD.
29+ *
30+ * <p>The ATM maintains internal mappings of customers and accounts for efficient
31+ * lookup operations and enforces business rules such as account existence validation.
32+ *
33+ * @see CheckingAccount
34+ * @see BusinessCheckingAccount
35+ * @see Customer
36+ * @see BusinessCustomer
37+ * @see Currency
38+ * @see CurrencyConverter
39+ * @since 1.0
40+ */
1041public class BankAtm {
1142
1243 private final Map <UUID , Customer > customerById = new HashMap <>();
1344 private final Map <String , CheckingAccount > accountByNumber = new HashMap <>();
45+ private final CurrencyConverter currencyConverter ;
46+
47+ /**
48+ * Creates a new BankAtm with default currency conversion support.
49+ *
50+ * <p>Initializes the ATM system with an empty set of accounts and customers,
51+ * and sets up currency conversion capabilities for multi-currency deposits.
52+ */
53+ public BankAtm () {
54+ this .currencyConverter = new CurrencyConverter ();
55+ }
1456
1557 /**
16- * Adds a checking account to the bank.
58+ * Adds a checking account to the ATM system.
59+ *
60+ * <p>This method accepts any type of checking account, including standard
61+ * {@link CheckingAccount} and {@link BusinessCheckingAccount} instances.
62+ * The account and all its owners are registered in the system for lookup operations.
63+ *
64+ * <p>After adding an account, customers can perform transactions using the
65+ * account number, and the account can be found using any owner's customer ID.
1766 *
18- * @param account The account to add.
67+ * @param account The checking account to add (including business accounts)
68+ * @throws NullPointerException if the account is null
69+ *
70+ * @see BusinessCheckingAccount
71+ * @see #findAccountsByCustomerId(UUID)
1972 */
2073 public void addAccount (CheckingAccount account ) {
2174 accountByNumber .put (account .getAccountNumber (), account );
@@ -40,14 +93,31 @@ public Set<CheckingAccount> findAccountsByCustomerId(UUID customerId) {
4093 }
4194
4295 /**
43- * Deposits funds into an account.
96+ * Deposits funds into an account with automatic currency conversion to USD.
97+ *
98+ * <p>This method accepts deposits in various currencies and automatically
99+ * converts the amount to USD using current exchange rates before depositing
100+ * into the account. All account balances are maintained in USD.
101+ *
102+ * <p>Supported currencies include USD, EUR, GBP, JPY, CAD, AUD, CHF, and CNY.
103+ * Exchange rates are managed by the internal {@link CurrencyConverter}.
104+ * For USD deposits, the amount is deposited directly without conversion overhead.
44105 *
45- * @param accountNumber The account number.
46- * @param amount The amount to deposit.
106+ * @param accountNumber The account number to deposit funds into
107+ * @param amount The amount to deposit in the specified currency
108+ * @param currency The currency of the deposit amount
109+ * @throws AccountNotFoundException if the account is not found or is closed
110+ * @throws IllegalArgumentException if the amount is negative
111+ * @throws IllegalArgumentException if the currency is null
112+ * @throws UnsupportedOperationException if the currency is not supported
113+ *
114+ * @see Currency
115+ * @see CurrencyConverter
47116 */
48- public void depositFunds (String accountNumber , double amount ) {
117+ public void depositFunds (String accountNumber , double amount , Currency currency ) {
49118 CheckingAccount account = getAccountOrThrow (accountNumber );
50- account .deposit (amount );
119+ double usdAmount = currencyConverter .convertToUsd (amount , currency );
120+ account .deposit (usdAmount );
51121 }
52122
53123 /**
0 commit comments