ATM Transaction Program in Java
Overview
In this blog, we will learn to build a Java program that will carry out a simple ATM transaction where the user can perform operations like withdraw, deposit and balance check.
Operations That Can Be Performed
- Withdraw
- Deposit
- Checking Balance
- Exit
Algorithm for Each Operation
A. Withdraw:
- Input the amount from the user that he/she wishes to withdraw.
- If the withdrawal amount is less than or equal to balance amount (i.e. withdrawalAmount ≤ balanceAmount), then perform the transaction (i.e. balanceAmount = balanceAmount — withdrawalAmount) and give the user’s desired amount.
- Else, print a message on the screen stating that the balance is insufficient.
B. Deposit:
- Input the amount from the user that he/she wishes to deposit.
- Add the deposit amount to the balance amount in the bank and update its value (i.e. balanceAmount = balanceAmount + depositAmount).
- Print a message on the screen stating that the transaction is successful.
C. Checking Balance:
When the user desires to check the balance amount in the bank, display the value of the balance amount on the screen.
D. Exit:
When the user chooses the exit option, exit the current transaction mode and end the program.
Source Code
Here is the complete source code of a Java program that carries out the operations of a simple ATM transaction:
Are you looking to master coding and crack top company interviews? Go ahead and try GUVI’s Pro Subscription to help you with everything needed to build a strong Technical Career.
Know more about GUVI:
Also, download GUVI’s app to learn the latest IT skills in vernacular languages.