1  /**
  2     A bank account has a balance that can be changed by 
  3     deposits and withdrawals.
  4  */
  5  public class BankAccount
  6  {
  7     private double balance;
  8  
  9     /**
 10        Constructs a bank account with a zero balance.
 11     */
 12     public BankAccount()
 13     {
 14        balance = 0;
 15     }
 16  
 17     /**
 18        Deposits money into the bank account.
 19        @param amount the amount to deposit
 20     */
 21     public void deposit(double amount)
 22     {
 23        System.out.print("Depositing " + amount);
 24        double newBalance = balance + amount;
 25        System.out.println(", new balance is " + newBalance);
 26        balance = newBalance;
 27     }
 28     
 29     /**
 30        Withdraws money from the bank account.
 31        @param amount the amount to withdraw
 32     */
 33     public void withdraw(double amount)
 34     {
 35        System.out.print("Withdrawing " + amount);
 36        double newBalance = balance - amount;
 37        System.out.println(", new balance is " + newBalance);
 38        balance = newBalance;
 39     }
 40     
 41     /**
 42        Gets the current balance of the bank account.
 43        @return the current balance
 44     */
 45     public double getBalance()
 46     {
 47        return balance;
 48     }
 49  }