ATM MACHINE SIMULATION
ATM MACHINE SIMULATION
This project simulates an ATM machine with essential banking operations such as balance inquiry,
deposit, withdrawal, PIN change, and viewing transaction history. It uses Java’s OOP features, such
as classes and methods, and allows users to interact with the ATM through a command-line
interface.
Features
Balance Inquiry: Displays the current account balance.
Cash Deposit: Allows users to deposit money into their account.
Cash Withdrawal: Allows users to withdraw money, ensuring sufficient balance.
PIN Change: Allows users to change their PIN after verifying the current one. Transaction
History: Displays the history of deposits, withdrawals, failed withdrawal attempts, and PIN
changes.
Security: The ATM allows up to 3 attempts to enter the correct PIN before locking the session.
Code Breakdown
2. Constructor
The constructor ATM(int pin, double initialBalance) initializes the ATM with a PIN and an
initial balance, and sets up the transaction history.
3. ATM Session ( start() method)
This method initiates the ATM session and presents the user with a menu to choose operations. It
keeps running until the user selects the option to exit.
5. Operations
Balance Inquiry: Displays the current balance to the user ( showBalance() method). Deposit
Cash: Adds a specified amount to the account balance and updates the transaction history (
depositCash() method).
Withdraw Cash: Withdraws a specified amount from the account balance if there are
sufficient funds, and logs the transaction ( withdrawCash() method). Change PIN: Allows
the user to change their PIN after verifying the current PIN
( changePin() method).
Transaction History: Displays all past transactions ( viewTransactionHistory() method).
7. Main Method
The main method creates an ATM object with a sample initial PIN (1234) and balance ($1000), then
starts the session.
!
1
2
3
4
5
6
!
132 public static void main(String[] args) {
133 ATM atm = new ATM(1234, 1000.0); // Example account with PIN 1234 and
134 atm.start();
135 }
136 }