1 import java.io.Serializable;
2
3 /**
4 A bank account has a balance that can be changed by
5 deposits and withdrawals.
6 */
7 public class BankAccount implements Serializable
8 {
9 private int accountNumber;
10 private double balance;
11
12 /**
13 Constructs a bank account with a zero balance.
14 @param anAccountNumber the account number for this account
15 */
16 public BankAccount(int anAccountNumber)
17 {
18 accountNumber = anAccountNumber;
19 balance = 0;
20 }
21
22 /**
23 Constructs a bank account with a given balance.
24 @param anAccountNumber the account number for this account
25 @param initialBalance the initial balance
26 */
27 public BankAccount(int anAccountNumber, double initialBalance)
28 {
29 accountNumber = anAccountNumber;
30 balance = initialBalance;
31 }
32
33 /**
34 Gets the account number of this bank account.
35 @return the account number
36 */
37 public int getAccountNumber()
38 {
39 return accountNumber;
40 }
41
42 /**
43 Deposits money into the bank account.
44 @param amount the amount to deposit
45 */
46 public void deposit(double amount)
47 {
48 double newBalance = balance + amount;
49 balance = newBalance;
50 }
51
52 /**
53 Withdraws money from the bank account.
54 @param amount the amount to withdraw
55 */
56 public void withdraw(double amount)
57 {
58 double newBalance = balance - amount;
59 balance = newBalance;
60 }
61
62 /**
63 Gets the current balance of the bank account.
64 @return the current balance
65 */
66 public double getBalance()
67 {
68 return balance;
69 }
70 }