Design and implement an ATM (Automated Teller Machine) system that allows users to perform basic banking operations such as balance inquiry, cash withdrawal, and cash deposit, with secure authentication and proper cash management.
- User Authentication: Users must authenticate using a card and PIN.
- Balance Inquiry: Users can check their account balance.
- Cash Withdrawal: Users can withdraw cash if sufficient balance and cash are available.
- Cash Deposit: Users can deposit cash into their account.
- Transaction Management: The system records and processes transactions (withdrawal, deposit).
- Banking Service Integration: The ATM interacts with a backend banking service to validate accounts and perform transactions.
- Cash Dispenser: The ATM manages its own cash inventory and dispenses cash securely.
- Concurrency & Consistency: The system handles concurrent access and ensures data consistency.
- User Interface: The ATM provides a user-friendly interface for operations.
- Extensibility: Easy to add new features such as mini-statements, fund transfers, or multi-currency support.
- ATM: Main class for ATM operations; interacts with
BankingServiceandCashDispenser. - Card: Represents an ATM card with card number and PIN.
- Account: Represents a bank account with account number and balance; supports debit and credit operations.
- Transaction (abstract): Base class for transactions; extended by
WithdrawalTransactionandDepositTransaction. - WithdrawalTransaction / DepositTransaction: Concrete transaction types for withdrawal and deposit.
- BankingService: Manages bank accounts and processes transactions; uses thread-safe data structures.
- CashDispenser: Manages the ATM's cash inventory and handles dispensing; ensures thread safety.
- ATMDemo: Demonstrates the usage of the ATM system with sample accounts and operations.
- Fields: BankingService bankingService, CashDispenser cashDispenser
- Methods: authenticateUser(Card), checkBalance(String accountNumber), withdrawCash(String accountNumber, double amount), depositCash(String accountNumber, double amount)
- Fields: String cardNumber, String pin
- Fields: String accountNumber, double balance
- Methods: debit(double), credit(double), getBalance()
- Fields: String accountNumber, double amount, Date date
- Methods: process()
- Inherits: Transaction
- Methods: process()
- Fields: Map<String, Account> accounts
- Methods: createAccount(String, double), getAccount(String), processTransaction(Transaction)
- Fields: double cashAvailable
- Methods: dispenseCash(double), addCash(double), getCashAvailable()
- Methods: run() — demonstrates sample ATM operations
BankingService bankingService = new BankingService();
CashDispenser cashDispenser = new CashDispenser(10000);
ATM atm = new ATM(bankingService, cashDispenser);
bankingService.createAccount("1234567890", 1000.0);
bankingService.linkCardToAccount("Card1234567890", "1234", "1234567890");
Card card = bankingService.getCard("Card1234567890");
atm.authenticateUser(card);
double balance = atm.checkBalance("1234567890");
atm.withdrawCash("1234567890", 500.0);
atm.depositCash("1234567890", 200.0);See ATMDemo.java for a sample usage and simulation of the ATM system.
- Add mini-statements: Show recent transactions.
- Add fund transfers: Allow transfers between accounts.
- Add multi-currency support: Handle different currencies and conversions.