JAVA Program to write ATM Machine Logic using ‘if’ statement.
How does this program work?
- This code helps to how to write ATM program using ‘if’ statement.
Here is the code
public class atm
{
public static void main(String args[])
{
int p,c,m,w,f;
m=25000;
System.out.println("Enter a pin number");
Scanner obj=new Scanner(System.in);
p=obj.nextInt();
if(p==1234)
{
System.out.println("choose option") ;
System.out.println("1-Withdraw\n2-Balance Enquiry\n3-Fast Cash");
c=obj.nextInt();
if(c==1)
{
System.out.println("Please Enter a Withdraw Amount");
w=obj.nextInt();
if(w< m&&w%100==0)
System.out.println("Please Take Your Amount ="+w);
else
System.out.println("Invalid Cash");
}
else
if(c==2)
{
System.out.println("Your Available Amount ="+m);
}
else
if(c==3)
{
System.out.println("Choose Fast Cash Option");
System.out.println("1-5000\n2-10000\n3-15000\n4-20000");
f=obj.nextInt();
if(f==1&&5000< m)
{
System.out.println("Please Take 5000 Rs");
}
else
if(f==2&&10000< m)
{
System.out.println("Please Take 10000 Rs");
}
else
if(f==3&&15000< m)
{
System.out.println("Please Take 15000 Rs");
}
else
if(f==4&&20000< m)
{
System.out.println("Please Take 20000 Rs");
}
else
System.out.println("Invalid fast cash option");
}
else
System.out.println("Invalid Choose");
}
else
System.out.println("Pin Number is Wrong");
}
}