//---------------------------------------------------------------------------- // // Point.java // // written by: Simon Parsons // last modified: 19th September 2012 // // A class that represents a 2D point, with integer values. // // Based on the Point class from Flanagan "Java in a Nutshell, 5th Edition" // page 72. public class Point { // Attributes/fields are two integer values private int x, y; // Constructors: allow both or none of the attributes to be set at creation. // If neither are set, assume that they are zero. public Point(int x, int y){ this.x = x; this.y = y; } public Point(){ this.x = 0; this.y = 0; } // API for Point: allows x and y to be set and retrieved. public int getX(){ return x; } public int getY(){ return y; } public void setX(int x){ this.x = x; } public void setY(int y){ this.y = y; } // Private methods, just to show that you can have such things. private double distanceFromOrigin(){ return Math.sqrt(x*x + y*y); } }