void display() { System.out.println( accountNumber + "\t" + accountHolder + "\t" + balance ); }
(The string "\t" tells the compiler that you want the tab character.)
display()
Method
Since this method is a member of a CheckingAccount
object,
the object's data is accessed by using the variable name,
like accountNumber
.
The dot operator is needed outside of the object,
like account1.accountNumber
in the main method.
Another nice thing to do is to use the tabulation character "\t"
to align
the output better.
When the display()
has been defined,
the testing program can be more easily written:
class CheckingAccount
{
. . . . (Now including the display()
method.)
}
class CheckingAccountTester
{
public static void main( String[] args )
{
CheckingAccount account1 = new CheckingAccount( "123", "Bob", 100 );
account1.display() ;
account1.processDeposit( 2000 );
account1.processCheck( 1500 );
account1.display() ;
}
}
With this nice, new scaffolding in place, you must surely be eager to do further testing of the program. Add statements after the old statements in the test program that:
account2
account2
.
account2
.
account2
.