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
- Checking Balance
Algorithm for Each Operation
- 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.
- 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.
When the user chooses the exit option, exit the current transaction mode and end the program.
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:
GUVI | Learn to code in your native language
Coding Bootcamp . New Age GURUKULAM 3 months Intensive Project Based Learning program, where you will learn and gain a…
Also, download GUVI’s app to learn the latest IT skills in vernacular languages.