Advertisement
nawamkihafahd

Untitled

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