SHARE
TWEET

Untitled

a guest Jan 14th, 2020 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Christopher Tang Liang Hong
  2. //P1838789
  3. //DIT/FT/1B/02
  4.  
  5. package ATM_Application;
  6.  
  7. public class ATM {
  8.     private BankAccount[] bankObjects = new BankAccount[3];
  9.  
  10.     public ATM() {
  11.     }
  12.    
  13.      public int addMoney(BankAccount bankObj, double amount) {
  14.         if (bankObj != null) {
  15.             if (amount <= 0.0) {
  16.                 return 0;
  17.             } else {
  18.                 bankObj.addBal(amount);
  19.                 return 1;
  20.             }
  21.         } else {
  22.             return -2;
  23.         }
  24.     }
  25.    
  26.     public int withdrawMoney(BankAccount bankObj, double amount) {
  27.         if (bankObj != null && amount > 0.0) {
  28.             if (bankObj.getBal() >= amount) {
  29.                 bankObj.deductBal(amount);
  30.                 return 1;                
  31.             } else {
  32.                 return 0;
  33.             }
  34.         } else {
  35.             return -1;
  36.         }      
  37.     }
  38.      
  39.     public double checkAccBal(BankAccount bankObj) {
  40.         if (bankObj != null) {
  41.             return bankObj.getBal();
  42.         }
  43.         return 0.0;
  44.     }
  45.    
  46.     public int checkUserandPass(BankAccount[] bankArray, String accNum, String pass) {
  47.         int counter = 0;
  48.         for (BankAccount item: bankArray) {
  49.             if (item.getAccountNo().equals(accNum)) {
  50.                 if (item.getPass().equals(pass)) {
  51.                 return counter;
  52.                 } else {
  53.                 return -1;
  54.                 }
  55.             }
  56.             counter++;
  57.         }
  58.         return -2;
  59.     }
  60.      
  61.     public BankAccount setBankObj(BankAccount bankObj) {
  62.         BankAccount bankaccount = new BankAccount();
  63.         if (bankObj != null) {
  64.         bankaccount = bankObj;
  65.         }
  66.         return bankObj;
  67.     }
  68.    
  69.     public boolean changePass(BankAccount bankObj, String newPass) {
  70.         if (bankObj != null) {
  71.            bankObj.setPass(newPass);
  72.            return true;
  73.         } else {
  74.             return false;
  75.         }
  76.     }
  77.    
  78.     public boolean checkChangePass(String firstPass, String secondPass) {
  79.         return firstPass.equals(secondPass);
  80.     }
  81.    
  82.     public BankAccount[] instanceBankAccountObjects() {
  83.          BankAccount bankAccount1 = new BankAccount("2353535", "Password1", 200.0);
  84.          BankAccount bankAccount2 = new BankAccount("5252525", "Password2", 300.0);
  85.          BankAccount bankAccount3 = new BankAccount("7575757", "Password3", 999.0);
  86.          bankObjects[0] = bankAccount1;
  87.          bankObjects[1] = bankAccount2;
  88.          bankObjects[2] = bankAccount3;  
  89.          
  90.          return bankObjects;
  91.     }
  92. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top