// This class is a client of the Point1 class, that // is, it creates Point1 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 PointClient2 { public static void main(String[] args) { Point2 p1 = new Point2(); p1.x = 5; p1.y = 10; Point2 p2 = new Point2(); p2.x = 3; p2.y = -8; // We could translate the points manually // like this, but it is better to make a method. //p1.x += 2; //p1.y += 3; //p2.x += 4; //p2.y += 8; translate(p1, 2, 3); translate(p2, 4, 8); System.out.println("p1 = " + p1.x + ", " + p1.y); System.out.println("p2 = " + p2.x + ", " + p2.y); } // This method takes a point and adds dx to the x // and dy to the y. // This is considered bad style as the Point class // should do this itself. // Note: The word "static" means that this isn't // part of a blueprint for creating objects. public static void translate(Point2 p, int dx, int dy){ p.x += dx; p.y += dy; } }