Advertisement
Guest User

ATM Code

a guest
Jan 21st, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1.  
  2. package atm;
  3.  
  4. import javax.swing.JOptionPane;
  5.  
  6.  
  7. public class ATM {
  8.  
  9.  
  10.     public static void main(String[] args) {
  11.         int i; //switch(هذا لل)
  12.         int ps; //الباسورد المدخل
  13.         double balance = 1000.0;
  14.         int pw = 1234;
  15.         double amount; //نخزنوا فيه القيم ألي نبو نسحبوهن و نودعوهن
  16.        
  17.         String input = JOptionPane.showInputDialog(null,"input password");
  18.         ps = Integer.parseInt(input); //القيمة المدخلة من نوع سترينق فانحولها انتجير
  19.         if (pw == ps)
  20.             input = JOptionPane.showInputDialog(null,"choose option\n1:withdraw\n2:deposit\n3:check balance");
  21.         i = Integer.parseInt(input); // نخزنوا قيمة الاختيار في أي و انحولوها ألى انتجير
  22.         switch(i){
  23.             case 1:    //في حالت السحب
  24.                
  25.                 input = JOptionPane.showInputDialog(null,"input amount");
  26.                 amount = Integer.parseInt(input); //انسجلوا قيمة السحب كانتيجر
  27.                 if (amount <= balance){
  28.                 balance -= amount; //انقصوا من الحساب قبل ما نطبعوه
  29.                 JOptionPane.showMessageDialog(null, "Successful, new balance: "+balance);
  30.                 }else{ JOptionPane.showMessageDialog(null, "error");}
  31.                 break;
  32.            
  33.             case 2:
  34.                 input = JOptionPane.showInputDialog(null,"input amount");
  35.                 amount = Integer.parseInt(input);
  36.                 balance += amount;
  37.                 JOptionPane.showMessageDialog(null, "Successful, new balance: "+balance);
  38.                 break;
  39.                
  40.             case 3:
  41.                 JOptionPane.showMessageDialog(null, "balance: "+balance);
  42.                 break;
  43.         }
  44.                    
  45.        
  46.     }
  47.    
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement