Advertisement
Ramdan51-062

TollDatabase

Oct 26th, 2017
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. public class TollDatabase
  2. {
  3. private Account[] accounts;
  4. //private Account currentAccount;
  5.  
  6. public TollDatabase()
  7. {
  8. accounts = new Account[ 2 ];
  9. accounts[ 0 ] = new Account( 12345, 54321, 10000, 12000 );
  10. accounts[ 1 ] = new Account( 98765, 56789, 2000, 2000 );
  11. }
  12.  
  13. private Account getAccount(int accountNumber)
  14. {
  15. for ( Account currentAccount : accounts)
  16. {
  17. if(currentAccount.getAccountNumber() == accountNumber)
  18. return currentAccount;
  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) return userAccount.validatePIN(userPIN);
  28.  
  29. else return false;
  30. }
  31.  
  32. public int getAvailableBalance(int userAccountNumber)
  33. {
  34. return getAccount(userAccountNumber).getAvailableBalance();
  35. }
  36.  
  37. public int getTotalBalance(int userAccountNumber)
  38. {
  39. return getAccount(userAccountNumber).getTotalBalance();
  40.  
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement