Exercise 2: Creating a Test Program(Level 1)

In this exercise, you create a test program (also known as a test harness) to exercise a prebuilt class. Figure 1-1 shows the definition of the Account class using a Unified Modeling Languaje (UML) Class diagram.

Account
 
<<constructors>>
+Account(initBalance:double)
<<methods>>
+getBalance():double
+deposit(amt:double):void
+withdraw(amt:double:void

Figure 1-1 Backing Account Class

Preparation

Before you begin, change directories to projects/BankingPrj/ using the cd command in the terminal window.

cd ~/projects/BankingPrj/

Task 1 - Creating the TestAccount Class

Using a text editor, create the TestAccount file. This class acts as a program to create an Account object with an initial balance of 100. The test program will then deposit 50 and then withdraw 147. Finally, the test program must print out the balance of the class to the standard output stream.

Task 2 - Compiling the TestAccount Program

On the command line, use the javac command to compile the test program.

Task 3 - Runnig th TestAccount Program

On the command line, use java command to run the test program.