// CSE 142, Summer 2008 (Marty Stepp) // This program uses our Point class and creates/manipulates a few Point objects. // Today's version of the client program utilizes the Point's new methods, its // toString method, its constructor, and encapsulation (private fields). public class PointTest { public static void main(String[] args) { // create two Point objects Point p1 = new Point(2, 17); p1.setX(-5); // p1.x = -5; // illegal now! System.out.println(p1.getX()); Point p2 = new Point(-5, 23); //p2.x = -5; // p2.y = 23; // print information about the Point objects System.out.println(p1); // (2, 17) System.out.println(p2); // (0, 23) // shift the Points' positions several times p1.translate(6, 4); p1.translate(3, 9); p2.translate(32, 95); p2.translate(-52, 15); System.out.println(p1); // (2, 17) System.out.println(p2); // (0, 23) // compute some distances p1.setX(1); p1.setY(1); p2.setX(2); p2.setY(0); System.out.println("p1's distance from origin: " + p1.distanceFromOrigin()); System.out.println("p1's distance from p2: " + p1.distance(p2)); System.out.println("p1's distance from p1: " + p1.distance(p1)); } }