taufiq123

Untitled

Oct 26th, 2017
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1.  
  2. /**
  3.  * Write a description of class BankDatabase here.
  4.  *
  5.  * @author (your name)
  6.  * @version (a version number or a date)
  7.  */
  8. public class BankDatabase
  9. {
  10.     private Account[] accounts;
  11.    
  12.     public BankDatabase(){
  13.         accounts= new Account[2];
  14.         accounts[0]=new Account(12345,54321,10000.0,1200.0);
  15.         accounts[1]=new Account(98765,56789,200.0,200.0);
  16.     }
  17.    
  18.     private Account getAccount(int accountNumber){
  19.         for(Account currentAccount : accounts){
  20.             if(currentAccount.getAccountNumber()==accountNumber){
  21.                 return currentAccount;
  22.             }
  23.         }
  24.        
  25.         return null;
  26.     }
  27.    
  28.     public boolean authenticateUser(int userAccountNumber, int userPIN){
  29.        Account userAccount = getAccount(userAccountNumber);
  30.        if(userAccount!=null){
  31.            return userAccount.validatePIN(userPIN);
  32.         }
  33.        else
  34.         return false;
  35.     }
  36.    
  37.     public double getAvailableBalance(int userAccountNumber){
  38.         return getAccount(userAccountNumber).getAvailableBalance();
  39.     }
  40.    
  41.     public double getTotalBalance(int userAccountNumber){
  42.         return getAccount(userAccountNumber).getTotalBalance();
  43.     }
  44.    
  45.     public void credit(int userAccountNumber,double amount){
  46.         getAccount(userAccountNumber).credit(amount);
  47.     }
  48.    
  49.     public void debit(int userAccountNumber,double amount){
  50.         getAccount(userAccountNumber).debit(amount);
  51.     }
  52. }
Add Comment
Please, Sign In to add comment