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 int accountNumber;
8 private double balance;
9
10 /**
11 Constructs a bank account with a zero balance.
12 @param anAccountNumber the account number for this account
13 */
14 public BankAccount(int anAccountNumber)
15 {
16 accountNumber = anAccountNumber;
17 balance = 0;
18 }
19
20 /**
21 Constructs a bank account with a given balance.
22 @param anAccountNumber the account number for this account
23 @param initialBalance the initial balance
24 */
25 public BankAccount(int anAccountNumber, double initialBalance)
26 {
27 accountNumber = anAccountNumber;
28 balance = initialBalance;
29 }
30
31 /**
32 Gets the account number of this bank account.
33 @return the account number
34 */
35 public int getAccountNumber()
36 {
37 return accountNumber;
38 }
39
40 /**
41 Deposits money into the bank account.
42 @param amount the amount to deposit
43 */
44 public void deposit(double amount)
45 {
46 double newBalance = balance + amount;
47 balance = newBalance;
48 }
49
50 /**
51 Withdraws money from the bank account.
52 @param amount the amount to withdraw
53 */
54 public void withdraw(double amount)
55 {
56 double newBalance = balance - amount;
57 balance = newBalance;
58 }
59
60 /**
61 Gets the current balance of the bank account.
62 @return the current balance
63 */
64 public double getBalance()
65 {
66 return balance;
67 }
68 }