// Miya Natsuhara // 08-12-2019 // CSE142 // TA: Grace Hopper // A client program using the Point class (creating multiple Point instances and // asking for their distance from the origin). public class PointClient { public static void main(String[] args) { // construct a point at coordinates (3, 5) // construct a point at coordinates (12, 4) // example of using the 2-argument constructor to make new Points Point p1 = new Point(3, 5); System.out.println("Point p1: " + p1); Point p2 = new Point(-500, 4); System.out.println("Point p2: " + p2); // example of using the 0-argument constructor to make new Points Point p3 = new Point(); System.out.println("Point p3: " + p3); System.out.println("After translate:"); // translate p1 by (-1, -2) p1.translate(-1, -2); // translate p2 by (10, 15) p2.translate(-500, 15); System.out.println("after translate:"); // NOTE: when we go to print out the Points, we can just print "p1" and // "p2" without explicitly having to call p1.toString() and p2.toString() // because Java knows to look for a method with exactly this signature // (return type, parameters, and name) when asked to convert an object to // a String representation. System.out.println("Point p1: " + p1); System.out.println("Point p2: " + p2); // formula: square root of (x^2 + y^2) // print p1 distance to origin System.out.println("Point p1's distance from origin: " + p1.distanceFromOrigin()); // print p2 distance to origin System.out.println("Point p2's distance from origin: " + p2.distanceFromOrigin()); // formula: square root of ((x1-x2)^2 + (y1-y2)^2) // print distance from p1 to p2 System.out.println("Distance from p1 to p2: " + p1.distanceFrom(p2)); // print distance from p2 to p1 System.out.println("Distance form p2 to p1: " + p2.distanceFrom(p1)); System.out.println("The sum of p1's coordinates is " + (p1.getX() + p2.getX()); p3.setLocation(100, 100); System.out.println("Point p3 after setLocation: " + p3); } }