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:       Constructs a bank account with a given balance.
17:       @param initialBalance the initial balance
18:    */
19:    public BankAccount(double initialBalance)
20:    {   
21:       balance = initialBalance;
22:    }
23: 
24:    /**
25:       Deposits money into the bank account.
26:       @param amount the amount to deposit
27:    */
28:    public void deposit(double amount)
29:    {  
30:       double newBalance = balance + amount;
31:       balance = newBalance;
32:    }
33: 
34:    /**
35:       Withdraws money from the bank account.
36:       @param amount the amount to withdraw
37:    */
38:    public void withdraw(double amount)
39:    {   
40:       double newBalance = balance - amount;
41:       balance = newBalance;
42:    }
43: 
44:    /**
45:       Gets the current balance of the bank account.
46:       @return the current balance
47:    */
48:    public double getBalance()
49:    {   
50:       return balance;
51:    }
52: 
53:    private double balance;
54: }