ATM Java Program – Source Code

DOWNLOAD SOURCE CODE HERE

package atm;
import javax.swing.JOptionPane;
public class ATM {
    public static void main(String[] args) {
        int balance=10000;
	int pas, wid, dep;
	int num;
	int back;
	int passuc=1234;
        
        JOptionPane.showMessageDialog(null, "Welcome to MyBank","ATM", 
                JOptionPane.INFORMATION_MESSAGE);
        
        pas=Integer.parseInt(JOptionPane.showInputDialog(null, "Please Enter Your Pin","ATM",
		JOptionPane.QUESTION_MESSAGE));
        
        if (pas==passuc){
            JOptionPane.showMessageDialog(null, "     Welcome     ");
            do
            {
                String f=JOptionPane.showInputDialog(null,"Please Choose Your Transaction\n"+"[1] Check Balance\n"
		+"[2] Withdraw\n"+"[3] Deposit\n"+"[4] Others\n", "MyBank",JOptionPane.QUESTION_MESSAGE);
                
                num=Integer.parseInt(f);
                if (num==1){
                    JOptionPane.showMessageDialog(null,"Your Balance is"+balance+"pesos","ATM",JOptionPane.INFORMATION_MESSAGE);
                }
                if (num==2){
                    wid=Integer.parseInt(JOptionPane.showInputDialog(null,"Please Enter Amount to Withdraw((Pesos)"
                            ,"ATM",JOptionPane.INFORMATION_MESSAGE));
                    if (wid<balance){
                        JOptionPane.showMessageDialog(null,"Insufficient Funds!","ATM",JOptionPane.ERROR_MESSAGE);
                    }
                    else{
                        balance=balance-wid;
                        JOptionPane.showMessageDialog(null,"Your Remaining Balance is"+balance,"ATM",JOptionPane.INFORMATION_MESSAGE);
                    }
                }
                if (num==3){
                    dep=Integer.parseInt(JOptionPane.showInputDialog(null,"Please Enter Amount to Deposit (Pesos)",
                            "ATM",JOptionPane.INFORMATION_MESSAGE));
                    balance=dep+balance;
                    JOptionPane.showMessageDialog(null,"Your Current Balance is"+balance,"ATM",JOptionPane.INFORMATION_MESSAGE);
                }
                if (num==4){
                    JOptionPane.showMessageDialog(null,"Change Pin Only","ATM",JOptionPane.ERROR_MESSAGE);
                    JOptionPane.showInputDialog(null,"Enter Current Pin","ATM",JOptionPane.ERROR_MESSAGE);
                    JOptionPane.showInputDialog(null,"Enter New Pin","ATM",JOptionPane.ERROR_MESSAGE);
                    JOptionPane.showMessageDialog(null,"You have successfully change your PIN","ATM",JOptionPane.INFORMATION_MESSAGE);
                }
                back=JOptionPane.showConfirmDialog(null,"Would you like to make another transaction","ATM",JOptionPane.YES_NO_OPTION);
        } 
            while(back==0);
                JOptionPane.showMessageDialog(null, "Thank you for making a transaction with us. We hope to see you again.");
        
    }
        else{
            JOptionPane.showMessageDialog(null,"Please re-enter PIN","Incorrect PIN",JOptionPane.ERROR_MESSAGE);
        }
        
    }
}

Post Author: techienomad

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.