// Ayaz Latif // TA: Grace Hopper // CSE 142 // 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 p1 at coordinates (3, 5) // construct a point p2 at coordinates (12, 4) // example of using the 2-argument constructor to make new Points Point p1 = new Point( 3, 5); Point p2 = new Point(12, 4); // example of using the 0-argument constructor to make new Points Point p3 = new Point(); System.out.println("Point p3: " + p3); // example of using getters to get x and y coords from Ponit class System.out.println("p1: x = " + p1.getX() + ", y = " + p1.getY()); // translate p1 by (-1, 4) // translate p2 by (6, 3) p1.translate(-1, 4); p2.translate(6, 3); // formula: square root of x^2 + y^2 // print p1 distance to origin double distanceOfP1 = p1.distanceFromOrigin(); System.out.println("distance from origin p1 = " + distanceOfP1); // formula: square root (x2 - x1)^2 + (x2 - x1)^2 // distance to another point double distanceBetween = p1.distanceTo(p2); System.out.println("distance between p1 and p2 = " + distanceBetween); // example of explicit and implicit calls to toString() System.out.println("p1 = " + p1.toString()); System.out.println("p2 = " + p2); } }