Java Program to Display the ATM Transaction
This is a Java Program to Display the ATM Transaction.
The user will choose from any one of the available options as input. Different cases using
switch case have been provided for different operations like withdraw, deposit and check
balance.
Here is the source code of the Java Program to Display the ATM Transaction. The Java
program is successfully compiled and run on a Windows system. The program output is
also shown below.
1. import [Link];
2. public class ATM_Transaction
3. {
4. public static void main(String args[] )
5. {
6. int balance = 5000, withdraw, deposit;
7. Scanner s = new Scanner([Link]);
8. while(true)
9. {
10. [Link]("Automated Teller Machine");
11. [Link]("Choose 1 for Withdraw");
12. [Link]("Choose 2 for Deposit");
13. [Link]("Choose 3 for Check Balance");
14. [Link]("Choose 4 for EXIT");
15. [Link]("Choose the operation you want to perform:");
16. int n = [Link]();
17. switch(n)
18. {
19. case 1:
20. [Link]("Enter money to be withdrawn:");
21. withdraw = [Link]();
22. if(balance >= withdraw)
23. {
24. balance = balance - withdraw;
25. [Link]("Please collect your money");
26. }
27. else
28. {
29. [Link]("Insufficient Balance");
30. }
31. [Link]("");
32. break;
33.
34. case 2:
35. [Link]("Enter money to be deposited:");
36. deposit = [Link]();
37. balance = balance + deposit;
38. [Link]("Your Money has been successfully
depsited");
39. [Link]("");
40. break;
41.
42. case 3:
43. [Link]("Balance : "+balance);
44. [Link]("");
45. break;
46.
47. case 4:
48. [Link](0);
49. }
50. }
51. }
52. }
Output:
$ javac ATM_Transaction.java
$ java ATM_Transaction
Automated Teller Machine
Choose 1 for Withdraw
Choose 2 for Deposit
Choose 3 for Check Balance
Choose 4 for EXIT
Choose the operation you want to perform:1
Enter money to be withdrawn:2000
Please collect your money
Automated Teller Machine
Choose 1 for Withdraw
Choose 2 for Deposit
Choose 3 for Check Balance
Choose 4 for EXIT
Choose the operation you want to perform:3
Balance : 3000
Automated Teller Machine
Choose 1 for Withdraw
Choose 2 for Deposit
Choose 3 for Check Balance
Choose 4 for EXIT
Choose the operation you want to perform:4
1. import [Link];
2. public class ATM_Transaction
3. {
4. public static void main(String args[] )
5. {
6. int balance = 5000, withdraw, deposit;
7. Scanner s = new Scanner([Link]);
8. while(true)
9. {
10. [Link]("Automated Teller Machine");
11. [Link]("Choose 1 for Withdraw");
12. [Link]("Choose 2 for Deposit");
13. [Link]("Choose 3 for Check Balance");
14. [Link]("Choose 4 for EXIT");
15. [Link]("Choose the operation you want to perform:");
16. int n = [Link]();
17. switch(n)
18. {
19. case 1:
20. [Link]("Enter money to be withdrawn:");
21. withdraw = [Link]();
22. if(balance >= withdraw)
23. {
24. balance = balance - withdraw;
25. [Link]("Please collect your money");
26. }
27. else
28. {
29. [Link]("Insufficient Balance");
30. }
31. [Link]("");
32. break;
33.
34. case 2:
35. [Link]("Enter money to be deposited:");
36. deposit = [Link]();
37. balance = balance + deposit;
38. [Link]("Your Money has been successfully
depsited");
39. [Link]("");
40. break;
41.
42. case 3:
43. [Link]("Balance : "+balance);
44. [Link]("");
45. break;
46.
47. case 4:
48. [Link](0);
49. }
50. }
51. }
52. }
Output:
$ javac ATM_Transaction.java
$ java ATM_Transaction
Automated Teller Machine
Choose 1 for Withdraw
Choose 2 for Deposit
Choose 3 for Check Balance
Choose 4 for EXIT
Choose the operation you want to perform:1
Enter money to be withdrawn:2000
Please collect your money
Automated Teller Machine
Choose 1 for Withdraw
Choose 2 for Deposit
Choose 3 for Check Balance
Choose 4 for EXIT
Choose the operation you want to perform:3
Balance : 3000
Automated Teller Machine
Choose 1 for Withdraw
Choose 2 for Deposit
Choose 3 for Check Balance
Choose 4 for EXIT
Choose the operation you want to perform:4