public class Deposit extends Transaction
1: // Deposit.java
2: // Represents a deposit ATM transaction
3:
4: public class Deposit extends Transaction
5: {
6: private double amount; // amount to deposit
7: private Keypad keypad; // reference to keypad
8: private DepositSlot depositSlot; // reference to deposit slot
9: private final static int CANCELED = 0; // constant for cancel option
10:
11: // Deposit constructor
12: public Deposit( int userAccountNumber, Screen atmScreen,
13: BankDatabase atmBankDatabase, Keypad atmKeypad,
14: DepositSlot atmDepositSlot )
15: {
16: // initialize superclass variables
17: super( userAccountNumber, atmScreen, atmBankDatabase );
18:
19: // initialize references to keypad and deposit slot
20: keypad = atmKeypad;
21: depositSlot = atmDepositSlot;
22: } // end Deposit constructor
23:
24: // perform transaction
25: public void execute()
26: {
27: BankDatabase bankDatabase = getBankDatabase(); // get reference
28: Screen screen = getScreen(); // get reference
29:
30: amount = promptForDepositAmount(); // get deposit amount from user
31:
32: // check whether user entered a deposit amount or canceled
33: if ( amount != CANCELED )
34: {
35: // request deposit envelope containing specified amount
36: screen.displayMessage(
37: "\nPlease insert a deposit envelope containing " );
38: screen.displayDollarAmount( amount );
39: screen.displayMessageLine( "." );
40:
41: // receive deposit envelope
42: boolean envelopeReceived = depositSlot.isEnvelopeReceived();
43:
44: // check whether deposit envelope was received
45: if ( envelopeReceived )
46: {
47: screen.displayMessageLine( "\nYour envelope has been " +
48: "received.\nNOTE: The money just deposited will not " +
49: "be available until we verify the amount of any " +
50: "enclosed cash and your checks clear." );
51:
52: // credit account to reflect the deposit
53: bankDatabase.credit( getAccountNumber(), amount );
54: } // end if
55: else // deposit envelope not received
56: {
57: screen.displayMessageLine( "\nYou did not insert an " +
58: "envelope, so the ATM has canceled your transaction." );
59: } // end else
60: } // end if
61: else // user canceled instead of entering amount
62: {
63: screen.displayMessageLine( "\nCanceling transaction..." );
64: } // end else
65: } // end method execute
66:
67: // prompt user to enter a deposit amount in cents
68: private double promptForDepositAmount()
69: {
70: Screen screen = getScreen(); // get reference to screen
71:
72: // display the prompt
73: screen.displayMessage( "\nPlease enter a deposit amount in " +
74: "CENTS (or 0 to cancel): " );
75: int input = keypad.getInput(); // receive input of deposit amount
76:
77: // check whether the user canceled or entered a valid amount
78: if ( input == CANCELED )
79: return CANCELED;
80: else
81: {
82: return ( double ) input / 100; // return dollar amount
83: } // end else
84: } // end method promptForDepositAmount
85: } // end class Deposit
86:
87:
88:
89: /**************************************************************************
90: * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
91: * Pearson Education, Inc. All Rights Reserved. *
92: * *
93: * DISCLAIMER: The authors and publisher of this book have used their *
94: * best efforts in preparing the book. These efforts include the *
95: * development, research, and testing of the theories and programs *
96: * to determine their effectiveness. The authors and publisher make *
97: * no warranty of any kind, expressed or implied, with regard to these *
98: * programs or to the documentation contained in these books. The authors *
99: * and publisher shall not be liable in any event for incidental or *
100: * consequential damages in connection with, or arising out of, the *
101: * furnishing, performance, or use of these programs. *
102: *************************************************************************/