In this tutorial you will learn about the ATM program In Java and its application with practical example.
In this tutorial, we will learn to create a Java Program of ATM program In Java programming.
Before starting with this tutorial we assume that you are best aware of the following Java programming topics:
- Java Operators.
- Basic Input and Output function in Java.
- Class and Object in Java.
- Basic Java programming.
- If-else statements in Java.
- For loop in Java.
Here we Build a Java Program, to show how ATM Transaction takes place,here a User has to choose options which are displayed on the Screen.
Following operations available in the ATM.
- Check Balance
Create a ATM program In Java programming.
In this program , we will create a ATM Mechanism In Java, we can create an ATM program for representing ATM transaction we will use options related to withdraw money, deposit, check balance, and exit from transaction.Let look at the code of this program.
//java program to create a ATM Program using swicth case..
public class ATM
//declare variables and take a value from user at run time
public static void main(String args )
int bal = 100000, with_draw, deposit;
Scanner sc = new Scanner(System.in);
System.out.println("Choose 1 for Withdraw");
System.out.println("Choose 2 for Deposit");
System.out.println("Choose 3 for Check Balance");
System.out.println("Choose 4 for EXIT");
System.out.print("Choose any operation you want to perform:");
//take a choice from user
int ch = sc.nextInt();
System.out.print("Enter money to be withdrawn from a/c:");
//get the withdrawl amount from user..
with_draw = sc.nextInt();
//check conditon for balance is greater than or equal to the withdrawal amount .
if(bal >= with_draw)
//Deduct the withdrawl amount from total balance
bal = bal - with_draw;
System.out.println("Please collect your money");
//show erroe if amount is greater than balanace
System.out.print("Enter money to be deposited:");
//get deposite amount from te user
deposit = sc.nextInt();
//add amount to the total balanace .
bal = bal + deposit;
System.out.println("Your Money has been successfully depsited");
//displaying balance of the user..
System.out.println("Balance : "+bal);
//exit from the menu
In the above program, we have first declared and initialized a set variables required in the program.
- bal = it will hold balance amount.
- with_draw= it wil hold value of prime number.
- deposit= it will hold deposit.
After declaring variables we take a nth value of from user.
Now user will choose any one available options and input the number with.here we use different cases using switch case that have been provided to user like withdraw, deposit and check balance.As shown in the image suppose user choose the option 3 then the output of program is show balance.
and again ask user to input different value for perform different operations.
following are the switch case condition according to option for different case are as follow
case 1: for withdraw.
case 2: for Deposit
Case 3: for Check Balance.
Case 4 : for exit
Approach to Check Balance
show the balance amount in the screen.