We print the value that is returned by the getX method, and then we print a message
that describes what value we expect to see.
This is a very important step. You want to spend some time thinking what the expected
result is before you run a test program. This thought process will help you understand
how your program should behave, and it can help you track down errors at an early
Determining the expected result in advance is an important part of testing.
In our case, the rectangle has been constructed with the top left corner at (5, 10). The
x-direction is moved by 15 pixels, so we expect an x-value of 5+15=20 after the
Here is a complete program that tests the moving of a rectangle.
1 import java.awt.Rectangle;
3 public class MoveTester
5 public static void main(String args)
7 Rectangle box = new Rectangle( 5 , 10 ,
20 , 30 );
9 // Move the rectangle
10 box.translate( 15 , 25 );
12 // Print information about the moved rectangle
13 System.out.print( Ðx: Ñ );
15 System.out.println( ÐExpected: 20Ñ );
17 System.out.print( Ðy: Ñ );
19 System.out.println( ÐExpected: 35Ñ );