1   // joi/1/bank/BankAccount.java                         
2   //                                                            
3   //                                                            
4   // Copyright 2003 Bill Campbell and Ethan Bolker                         
5                                                               
6   /**
7    * A BankAccount object has a private field to keep track 
8    * of this account's current balance, and public methods to 
9    * return and change the balance.
10   *
11   * @see Bank
12   * @version 1
13   */
14  
15  public class BankAccount
16  {
17      private int balance;  // work only in whole dollars
18      
19      /**
20       * A constructor for creating a new bank account.
21       *
22       * @param initialBalance the opening balance.
23       */
24  
25      public BankAccount( int initialBalance )
26      {
27          this.deposit( initialBalance );
28      }
29  
30      /**
31       * Withdraw the amount requested.
32       *
33       * @param amount the amount to be withdrawn.
34       */
35  
36      public void withdraw( int amount )
37      {
38          balance = balance - amount;
39      }
40      
41      /**
42       * Deposit the amount requested.
43       *
44       * @param amount the amount to be deposited.
45       */
46  
47      public void deposit( int amount )
48      {
49          balance = balance + amount;
50      }
51  
52      /**
53       * The current account balance.
54       *
55       * @return the current balance.
56       */
57  
58      public int getBalance()
59      {
60          return balance;
61      }
62  }
63