Java Reference
In-Depth Information
We have now completed the implementation of the BankAccount classȌsee the
code listing below. There is only one step remaining: testing that the class works
correctly. That is the topic of the next section.
ch03/account/BankAccount.java
1 /**
2 A bank account has a balance that can be
changed by
3 deposits and withdrawals.
4 */
5 public class BankAccount
6 {
7 /**
8 Constructs a bank account with a
zero balance.
9 */
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;
97
98
Search WWH ::




Custom Search