Java Reference
In-Depth Information
32
for
(BankAccount a : accounts)
33 {
34 total = total + a.getBalance();
35 }
36
return
total;
37 }
38
39 /**
40
Counts the number of bank accounts whose
balance is at
41
least a given value.
42 @param atLeast
the balance required to
count an account
43 @return
the number of accounts having at
least the given balance
44 */
45
public int
count(
double
atLeast)
46 {
47
int
matches =
0
;
48
for
(BankAccount a : accounts)
49 {
50
if
(a.getBalance() >= atLeast)
matches++;
//
Found a match
51 }
52
return
matches;
53 }
54
55 /**
56
Finds a bank account with a given number.
57 @param accountNumber
the number to find
58 @return
the account with the given
number, or null if there
59
is no such account
60 */
61
public
BankAccount find(
int
accountNumber)
62 {
63
for
(BankAccount a : accounts)
64 {
65
if
(a.getAccountNumber() ==
accountNumber)
//
Found a match
66
return
a;
67 }
68
return null
;
// No match in the entire array list
69 }