// Improved point client: this version takes // advantage of some additional functionality // that we've added to the Point class: // - constructors // - toString() // - distanceFrom(Point other) method // // Note that since I called this version of the Point class // Point2, I had to rename the object everywhere: public class PointClient2 { public static void main(String[] args) { // Creating a constructor in the Point class // lets us simply the creation of a point: // Point p1 = new Point(); // p1.x = 3; // p1.y = 5; --> turns into: Point2 p1 = new Point2(3, 5); // Adding a toString() method lets us simply // printing out a Point: // System.out.println("p1.x = " + p1.x + ", p1.y = " + p1.y); // turns into: System.out.println("p1 = " + p1); p1.translate(2, 8); System.out.println("p1 = " + p1); System.out.println("p1's distance from origin = " + p1.distanceFromOrigin()); Point2 p2 = new Point2(10, -5); System.out.println("p2 = " + p2); p2.translate(-5, 16); System.out.println("p2 = " + p); System.out.println("p2's distance from origin = " + p2.distanceFromOrigin()); // Implementing a distanceFrom method in the Point // class allows us to ask one Point how far it is // from another: double distance = p1.distanceFrom(p2); System.out.println("p1 -> p2 = " + distance); } } // procedural programming // main method, run, DO some stuff // Object-Oriented programming (OOPSLA) // objects, conversations inbetween different kinds of objects // Objects // Scanners, Files, PrintStreams, Graphics, DrawingPanel // group related data together // state --> stuff we need to remember // behavior --> things we can ask our object to do // Scanner // state --> what file it's reading, cursor // behavior --> nextLine(), next(), nextInt(), hasNext() // Clients v. Implementors