Point.java |
| /* Point.java Stewart Fleming March 2001 Implements requirements for measurement system, requirement 11.1 Point */ package jlittle_ex2; /** * Simple class to represent a point with integer X and Y coordinates. */ public class Point { // requirement 11.1.1 int xCoord, yCoord; /** Default points are constructed at the origin */ Point() { xCoord = yCoord = 0; } /** Construct a point at the specified location */ Point(int x, int y) { xCoord = x; yCoord = y; } /** Change the X coordinate of the point. */ void setX(int x) { xCoord = x; } /** Returns the X coordinate of the point */ int getX() { return xCoord; } /** Change the Y coordinate of the point. */ void setY(int y) { yCoord = y; } /** Returns the Y coordinate of the point */ int getY() { return yCoord; } /** * Test equality between two points. * Two points are equal if both X and Y coordinates are equal. * Requirement 11.1.2 */ boolean equals(Point p) { return ((xCoord == p.getX()) && (yCoord == p.getY())); } /** * Calculate the distance between two points. * Requirement 11.1.3 */ double Distance(Point p) { long dx, dy; dx = (p.getX() - xCoord); dy = (p.getY() - yCoord); return Math.sqrt((dx * dx) + (dy * dy)); } } // end of class Point |
James Little |