Java Reference
In-Depth Information
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 balance = balance + amount;
31 }
32
33 /**
34
Withdraws money from the bank account.
35 @param amount
the amount to withdraw
36 */
37
public void
withdraw(
double
amount)
38 {
39 balance = balance - amount;
40 }
41
42 /**
43
Gets the current balance of the bank account.
44 @return
the current balance
45 */
46
public double
getBalance()
47 {
48
return
balance;
49 }
50
51 /**
52
Transfers money from the bank account to another account.
53 @param amount
the amount to transfer
54 @param other
the other account
55 */
56
public void
transfer(
double
amount,
BankAccount other)
57 {
58 withdraw(amount);
59 other.deposit(amount);
60 }
61
457
458