AndreanJP

Class BankDatabase

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