/** Represents a Cartesian (x,y) point */
public class Point {
public double x, y; // The coordinates of the point
public Point(double x, double y) { // A constructor that
this.x = x; this.y = y; // initializes the fields
}
public double distanceFromOrigin() { // A method that operates on
return Math.sqrt(x*x + y*y); // the x and y fields
}
}
|