Java Program to Display the ATM Transaction
Lets Build a Java Program, to represent ATM Transaction, where a User has to choose input from the options displayed on the Screen. The available options on the Screen include operations such as Withdraw, deposit, balance.
Following are the basic operations available in the ATM
- Check Balance
Approach to each Option
- Take the amount user desires to withdraw as input.
- If the balance amount greater than or equal to the withdrawal amount then Perform the transaction and give the user the desired amount.
- Else print Insufficient Funds message.
- Take the amount user desires to deposit as input.
- Add the received input from the user to balance and update its value.
- balance = balance + deposit.
- Print a message on screen stating deposit transaction has been successful.
C. Check Balance:
- Print a message on screen showing the value of balance amount.
- Exit the current Transaction mode and return the user to the home page or initial screen.
Below is the implementation of the above approach.
Current Balance : 10000 Withdrawn Operation: Withdrawing Amount : 5000 Please collect your money and collect the card Current Balance : 5000 Deposit Operation: Depositing Amount : 2000 Your Money has been successfully deposited Balance : 7000
Time Complexity: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.