From BluWiki
public class PointTester
{
public static void main(String[] args)
{
System.out.println("Testing distance calculations:");
System.out.println("");
System.out.println("Test three points on a horizontal line, (-2,0) , (0,0) , and (2,0) ...");
System.out.println("");
TwoDimensionalPoint p1 = new TwoDimensionalPoint(-2,0);
TwoDimensionalPoint p2 = new TwoDimensionalPoint(0,0);
TwoDimensionalPoint p3 = new TwoDimensionalPoint(2,0);
//calculate the distance between p1 and p2
System.out.println("The Distance between " + p1.toString() + " and " + p2.toString() + " is: " + p1.perform("distance", p2) );
//calculate the distance between p2 and p3
System.out.println("The Distance between " + p2.toString() + " and " + p3.toString() + " is: " + p2.perform("distance", p3) );
//calculate the distance between p1 and p3
System.out.println("The Distance between " + p1.toString() + " and " + p3.toString() + " is: " + p1.perform("distance", p3) );
System.out.println("");
System.out.println("Reversing the order of the arguments should give the same result...");
System.out.println("");
//calculate the distance between p1 and p2
System.out.println("The Distance between " + p1.toString() + " and " + p2.toString() + " is: " + p2.perform("distance", p1) );
//calculate the distance between p2 and p3
System.out.println("The Distance between " + p2.toString() + " and " + p3.toString() + " is: " + p3.perform("distance", p2) );
//calculate the distance between p1 and p3
System.out.println("The Distance between " + p1.toString() + " and " + p3.toString() + " is: " + p3.perform("distance", p1) );
/* Troubleshooting code
System.out.println("");
System.out.println("It doesn't, so let's break the second case down into its components...");
System.out.println("");
//calculate the horizontal distance between p2 and p3
System.out.println("The x distance between " + p2.toString() + " and " + p3.toString() + " is: " + p2.xDistance(p3) );
//calculate the horizontal distance between p3 and p2
System.out.println("The x distance between " + p3.toString() + " and " + p2.toString() + " is: " + p3.xDistance(p2) + " ORDER REVERSED" );
System.out.println("-----------------");
//calculate the vertical distance between p2 and p3
System.out.println("The y distance between " + p2.toString() + " and " + p3.toString() + " is: " + p2.yDistance(p3) );
//calculate the horizontal distance between p3 and p2
System.out.println("The y distance between " + p3.toString() + " and " + p2.toString() + " is: " + p3.yDistance(p2) + " ORDER REVERSED" );
//calculate the distance between p2 and p3
System.out.println("The Distance between " + p2.toString() + " and " + p3.toString() + " is: " + p3.perform("distance", p2) );
End troubleshooting Code */
//Test three points on a horizontal line.
System.out.println("");
System.out.println("Test three points on a vertical line, (0,0) , (0,-2) , and (0,3) ...");
System.out.println("");
p1.setLocation(0,0);
p2.setLocation(0,-2);
p3.setLocation(0,3);
//calculate the distance between p1 and p2
System.out.println("The Distance between " + p1.toString() + " and " + p2.toString() + " is: " + p1.perform("distance", p2) );
//calculate the distance between p2 and p3
System.out.println("The Distance between " + p2.toString() + " and " + p3.toString() + " is: " + p2.perform("distance", p3) );
//calculate the distance between p1 and p3
System.out.println("The Distance between " + p1.toString() + " and " + p3.toString() + " is: " + p1.perform("distance", p3) );
System.out.println("");
System.out.println("Reversing the order of the arguments should give the same result...");
System.out.println("");
//calculate the distance between p1 and p2
System.out.println("The Distance between " + p1.toString() + " and " + p2.toString() + " is: " + p2.perform("distance", p1) );
//calculate the distance between p2 and p3
System.out.println("The Distance between " + p2.toString() + " and " + p3.toString() + " is: " + p3.perform("distance", p2) );
//calculate the distance between p1 and p3
System.out.println("The Distance between " + p1.toString() + " and " + p3.toString() + " is: " + p3.perform("distance", p1) );
System.out.println("----------------");
System.out.println("Now testing slope calculations:");
System.out.println("");
p1.setLocation(0,0);
p2.setLocation(0,0);
System.out.println("Slope between two identical points " + p1.toString() + " and " + p2.toString() + ": " + p1.perform("gradient",p2) );
p1.setLocation(0,0);
p2.setLocation(0,4);
System.out.println("Slope between two vertically aligned points " + p2.toString() + " and " + p1.toString() + ": " + p2.perform("gradient",p1) );
System.out.println("");
System.out.println("Reversing the order of the arguments should give the same result...");
System.out.println("");
p1.setLocation(0,0);
p2.setLocation(0,0);
System.out.println("Slope between two identical points " + p2.toString() + " and " + p1.toString() + ": " + p2.perform("gradient",p1) );
p1.setLocation(0,0);
p2.setLocation(0,4);
System.out.println("Slope between two vertically aligned points " + p1.toString() + " and " + p2.toString() + ": " + p1.perform("gradient",p2) );
System.out.println("----------------");
System.out.println("Now testing angle calculations:");
System.out.println("");
p1.setLocation(0,0);
p2.setLocation(0,0);
System.out.println("Angle between two identical points " + p2.toString() + " and " + p1.toString() + ": " + p2.perform("angle",p1) );
p1.setLocation(0,0);
p2.setLocation(0,4);
System.out.println("Angle between two vertically aligned points " + p1.toString() + " and " + p2.toString() + ": " + p1.perform("angle",p2) );
p1.setLocation(40,0);
p2.setLocation(-2,0);
System.out.println("Angle between two horizontally aligned points " + p1.toString() + " and " + p2.toString() + ": " + p1.perform("angle",p2) );
p1.setLocation(-4,-4);
p2.setLocation(4,4);
System.out.println("Angle between two points " + p1.toString() + " and " + p2.toString() + ": " + p1.perform("angle",p2) );
System.out.println("Reversed: " + p2.toString() + " and " + p1.toString() + ": " + p2.perform("angle",p1) );
System.out.println("----------------");
System.out.println("Now testing alignment calculations:");
System.out.println("");
p1.setLocation(0,0);
p2.setLocation(0,0);
p3.setLocation(45,90);
System.out.println("Two identical points, one unique, " + p1.toString() + ", " + p2.toString() + " and " + p3.toString() + " are on the same line: " + p1.areAligned(p2,p3) );
p1.setLocation(5296,5296);
p2.setLocation(5296,5296);
p3.setLocation(5296,5296);
System.out.println("Three identical points, " + p1.toString() + ", " + p2.toString() + " and " + p3.toString() + " are on the same line: " + p1.areAligned(p2,p3) );
}//end main
}//end PointTester class