nawamkihafahd

Untitled

Oct 19th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. public class Deposit extends Transaction
  2. {
  3. private double amount;
  4. private Keypad keypad;
  5. private DepositSlot depositSlot;
  6. private final static int CANCELED = 0;
  7.  
  8. public Deposit( int userAccountNumber, Screen atmScreen,
  9. BankDatabase atmBankDatabase, Keypad atmKeypad,
  10. DepositSlot atmDepositSlot )
  11. {
  12. super( userAccountNumber, atmScreen, atmBankDatabase );
  13.  
  14. keypad = atmKeypad;
  15. depositSlot = atmDepositSlot;
  16. }
  17.  
  18. @Override
  19. public void execute()
  20. {
  21. BankDatabase bankDatabase = getBankDatabase();
  22. Screen screen = getScreen();
  23.  
  24. amount = promptForDepositAmount();
  25.  
  26. if ( amount != CANCELED )
  27. {
  28. screen.displayMessage( "\nPlease insert a deposit envelope containing " );
  29. screen.displayDollarAmount( amount );
  30. screen.displayMessageLine( "." );
  31.  
  32. boolean envelopeReceived = depositSlot.isEnvelopeReceived();
  33.  
  34. if ( envelopeReceived )
  35. {
  36. screen.displayMessageLine( "\nYour envelope has been " +
  37. "received.\nNOTE: The money just deposited will not " +
  38. "be available until we verify the amount of any " +
  39. "enclosed cash and your checks clear." );
  40. bankDatabase.credit( getAccountNumber(), amount );
  41. }
  42. else
  43. {
  44. screen.displayMessageLine( "\nYou did not insert an " +
  45. "envelope, so the ATM has canceled your transaction." );
  46. }
  47. }
  48. else
  49. {
  50. screen.displayMessageLine( "\nCanceling transaction..." );
  51. }
  52. }
  53.  
  54. private double promptForDepositAmount()
  55. {
  56. Screen screen = getScreen();
  57.  
  58. screen.displayMessage( "\nPlease enter a deposit amount in " +
  59. "CENTS (or 0 to cancel): " );
  60. int input = keypad.getInput();
  61.  
  62. if ( input == CANCELED )
  63. return CANCELED;
  64. else
  65. return ( double ) input / 100;
  66. }
  67. }
Add Comment
Please, Sign In to add comment