01: /**
02:    A bank account has a balance that can be changed by 
03:    deposits and withdrawals.
04: */
05: public class BankAccount
06: {
07:    /**
08:       Constructs a bank account with a zero balance
09:    */
10:    public BankAccount()
11:    {
12:       balance = 0;
13:    }
14: 
15:    /**
16:       Deposits money into the bank account.
17:       @param amount the amount to deposit
18:    */
19:    public synchronized void deposit(double amount)
20:    {
21:       System.out.print("Depositing " + amount);
22:       double newBalance = balance + amount;
23:       System.out.println(", new balance is " + newBalance);
24:       balance = newBalance;
25:       notifyAll();
26:    }
27:    
28:    /**
29:       Withdraws money from the bank account.
30:       @param amount the amount to withdraw
31:    */
32:    public synchronized void withdraw(double amount)
33:       throws InterruptedException
34:    {
35:       while (balance < amount)
36:          wait();
37:       System.out.print("Withdrawing " + amount);
38:       double newBalance = balance - amount;
39:       System.out.println(", new balance is " + newBalance);
40:       balance = newBalance;
41:    }
42:    
43:    /**
44:       Gets the current balance of the bank account.
45:       @return the current balance
46:    */
47:    public double getBalance()
48:    {
49:       return balance;
50:    }
51:    
52:    private double balance;
53: }