public class Account
1: // Fig. 3.13: Account.java
2: // Account class with a constructor to
3: // initialize instance variable balance.
4:
5: public class Account
6: {
7: private double balance; // instance variable that stores the balance
8:
9: // constructor
10: public Account( double initialBalance )
11: {
12: // validate that initialBalance is greater than 0.0;
13: // if it is not, balance is initialized to the default value 0.0
14: if ( initialBalance > 0.0 )
15: balance = initialBalance;
16: } // end Account constructor
17:
18: // credit (add) an amount to the account
19: public void credit( double amount )
20: {
21: balance = balance + amount; // add amount to balance
22: } // end method credit
23:
24: // return the account balance
25: public double getBalance()
26: {
27: return balance; // gives the value of balance to the calling method
28: } // end method getBalance
29:
30: } // end class Account
31:
32:
33: /**************************************************************************
34: * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
35: * Pearson Education, Inc. All Rights Reserved. *
36: * *
37: * DISCLAIMER: The authors and publisher of this book have used their *
38: * best efforts in preparing the book. These efforts include the *
39: * development, research, and testing of the theories and programs *
40: * to determine their effectiveness. The authors and publisher make *
41: * no warranty of any kind, expressed or implied, with regard to these *
42: * programs or to the documentation contained in these books. The authors *
43: * and publisher shall not be liable in any event for incidental or *
44: * consequential damages in connection with, or arising out of, the *
45: * furnishing, performance, or use of these programs. *
46: *************************************************************************/