// This class is a client of the Point class, that // is: it creates Point objects and uses them. // // Java can run this file as a program since it has // a public static void main(String[] args) method. public class PointClient { public static void main(String[] args) { // create p1 using the first constructor Point p1 = new Point(5, 10); // create p2 using the second constructor Point p2 = new Point(); p2.x = 3; p2.y = -8; //Note: Java by default calls ".toString()" if the class defines //it, so you can leave off ".toString()" and it works the same System.out.println("p1 = " + p1.toString()); System.out.println("p2 = " + p2); // The Point objects know how to handle translate() themselves, // so we ask them to do it. p1.translate(-10, 3); p2.translate(4, 8); // Ask the Point objects p1 and p2 their distance to the Origin System.out.println("Distance of p1 = " + p1.distanceFromOrigin()); System.out.println("Distance of p2 = " + p2.distanceFromOrigin()); System.out.println(); System.out.println("p1 = " + p1); System.out.println("p2 = " + p2); } }