Advertisement
rmword

Untitled

Oct 23rd, 2017
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 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.0);
  10. }
  11.  
  12. private 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.  
  26. if(userAccount != null)
  27. return userAccount.validatePIN(userPIN);
  28. else
  29. return false;
  30. }
  31.  
  32. public double getAvailableBalance(int userAccountNumber)
  33. {
  34. return getAccount(userAccountNumber).getAvailableBalance();
  35. }
  36.  
  37. public double getTotalBalance(int userAccountNumber)
  38. {
  39. return getAccount(userAccountNumber).getTotalBalance();
  40. }
  41.  
  42. public void credit(int userAccountNumber, double amount)
  43. {
  44. getAccount(userAccountNumber).credit(amount);
  45. }
  46.  
  47. public void debit(int userAccountNumber, double amount)
  48. {
  49. getAccount(userAccountNumber).debit(amount);
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement