/* * ========================================================= * Definition of class Point : A point is represented by its * (x,y) coordinates. * * Written By : Mark Austin October 1997 * ========================================================= */ public class Point { protected double dX, dY; // (x,y) coordinates of the Point // Constructor method : just create instance of class. public Point() { } // Create instance of class and set (x,y) coordinates. public Point( double dX, double dY ) { setPoint( dX, dY ); } // Set x and y coordinates of Point. public void setPoint( double dX, double dY ) { this.dX = dX; this.dY = dY; } // Get x and y coordinates. public double getX() { return dX; } public double getY() { return dY; } // Convert the point into a String representation public String toString() { return "[" + dX + ", " + dY + "]"; } // Exercise methods in point class. public static void main( String args[] ) { double dX, dY; System.out.println("Point test program"); System.out.println("==============================="); // Create two new points. Point point1 = new Point(); point1.setPoint( 1.0, 1.0 ); Point point2 = new Point( 1.5, 4.5 ); // Print (x,y) coordinates of points. System.out.println("Point 1 : " + point1.toString() ); System.out.println("Point 2 : " + point2.toString() ); // Get x and y coordinates. dX = point1.getX(); dY = point1.getY(); System.out.println("Point 1 : X coordinate = " + dX ); System.out.println(" Y coordinate = " + dY ); dX = point2.getX(); dY = point2.getY(); System.out.println("Point 2 : X coordinate = " + dX ); System.out.println(" Y coordinate = " + dY ); System.out.println("==============================="); System.out.println("End of Point test program"); } }