Java Reference
In-Depth Information
Here is a class to run methods of the BankAccount class. The main method
constructs an object of type BankAccount , invokes the deposit and withdraw
methods, and then displays the remaining balance on the console.
We also print the value that we expect to see. In our sample program, we deposit
$2,000 and withdraw $500. We therefore expect a balance of $1500.
ch03/account/BankAccountTester.java
1 /**
2 A class to test the BankAccount class.
3 */
4 public class BankAccountTester
5 {
6 /**
7 Tests the methods of the BankAccount
class.
8 @param args not used
9 */
10 public static void main(String[] args)
11 {
12 BankAccount harrysChecking = new
BankAccount();
13 harrysChecking.deposit( 2000 );
14 harrysChecking.withdraw( 500 );
15 System.out.println(harrysChecking.getBalance
16 System.out.println( "Expected: 1500" );
17 }
18 }
Output
1500
Expected: 1500
To produce a program, you need to combine the BankAccount and the
BankAccountTester classes. The details for building the program depend on
your compiler and development environment. In most environments, you need to
carry out these steps:
1. Make a new subfolder for your program.
Search WWH ::




Custom Search