Exercise 2: Creating a Test Program (Level 2)

In this exercise, you create a test harness (a test class) to exercise a pre-built class. These are the Level 2 instruccions which provide additional hints.

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.

Perform the following:
  1. Declare the TestAccount class.
  2. Add the main method:
    1. Declare a variable of type Account and initialize that variable by creating an instance of the Account class with an initial balance of 100.
    2. Use the deposit method to add 50 to the account.
    3. Use the withdraw method to subtract 147 from the account.
    4. Use the getBalance method to retrieve the new account balance and use the method System.out.println to display the balance 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.