Java Reference
In-Depth Information
7 {
8 Bank firstBankOfJava =
new
Bank();
9 firstBankOfJava.addAccount(
new
BankAccount(
1001
,
20000
));
10 firstBankOfJava.addAccount(
new
BankAccount(
1015
,
10000
));
11 firstBankOfJava.addAccount(
new
BankAccount(
1729
,
15000
));
12
13 Scanner in =
new
Scanner(System.in);
14
15
double
threshold = in.nextDouble();
16
int
c = firstBankOfJava.count(threshold);
17 System.out.println(
"Count: "
+ c);
18
int
expectedCount = in.nextInt();
19 System.out.println(
"Expected: "
+
expectedCount);
20
21
int
accountNumber = in.nextInt;
22 BankAccount a =
firstBankOfJava.find(accountNumber);
23
if
(a ==
null
)
24 System.out.println(
"No matching
account"
);
25
else
26 {
27 System.out.println(
"Balance of
maatching account: "
28 + a.getBalance());
29
int
matchingBalance = in.nextLine();
30 System.out.println(
"Expected: "
+
matchingBalance);
31 }
32 }
33 }
319
320
Rather than using fixed values for the threshold and the account number to be found,
the program reads these values, and the expected responses. By running the program
with different inputs, we can test different scenarios, such as the ones for diagnosing
off-by-one errors discussed in
Common Error 6.2
.
Of course, it would be tedious to type in the input values by hand every time the test
is executed. It is much better to save the inputs in a file, such as the following: