ATM Transaction Options
This program simulates ATM transaction options using if-else ladder.
Problem Statement
Write a Java program that simulates ATM transaction options like balance inquiry, deposit, and withdrawal using if-else ladder.
Source Code
| 1 | public class ATMOptions { |
| 2 | public static void main(String[] args) { |
| 3 | int choice = 2; |
| 4 | double balance = 5000; |
| 5 | if(choice == 1) { |
| 6 | System.out.println("Balance: " + balance + " - Eduinq"); |
| 7 | } else if(choice == 2) { |
| 8 | balance += 1000; |
| 9 | System.out.println("Deposit successful. New balance: " + balance + " - Eduinq"); |
| 10 | } else if(choice == 3) { |
| 11 | balance -= 1000; |
| 12 | System.out.println("Withdrawal successful. New balance: " + balance + " - Eduinq"); |
| 13 | } else { |
| 14 | System.out.println("Invalid choice - Eduinq"); |
| 15 | } |
| 16 | } |
| 17 | } |
Program Output
Deposit successful. New balance: 6000.0 - Eduinq
Explanation
The program uses an if-else ladder to simulate ATM transaction options. Each condition corresponds to a transaction: balance inquiry, deposit, or withdrawal. If the choice does not match any condition, the else block prints invalid choice. This demonstrates how if-else ladders can implement menu-driven systems, allowing users to select operations easily in financial applications. Shows how if-else ladder can simulate ATM transaction options.