Java Reference
In-Depth Information
14 accounts.add(
new
BankAccount(
1729
));
15 accounts.add(
1
, new BankAccount(
1008
));
16 accounts.remove(
0
);
17
18 System.out.println(
"Size: "
+
accounts.size()) ;
19 System.out.println(
"Expected: 3"
);
20 BankAccount first = accounts.get(
0
);
21 System.out.println(
"First account
number: "
22 + first.getAccountNumber());
23 System.out.println(
"Expected: 1008"
);
24 BankAccount last =
accounts.get(accounts.size() -
1
);
25 System.out.println(
"Last account number:
"
26 + last.getAccountNumber());
27 System.out.println(
"Expected: 1729"
);
28 }
29 }
ch07/arraylist/ArrayListTester.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 @param anAccountNumber
the account
number for this account
10 */
11
public
BankAccount(
int
anAccountNumber)
12 {
13 accountNumber = anAccountNumber;
14 balance =
0
;
15 }
16
17 /**
18
Constructs a bank account with a given
balance.