Advertisement
rmword

Untitled

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