public class Point
{ protected double x, y;

  public static final Point ORIGIN = new Point();
  
  public Point()
  { this.x = 0;
    this.y = 0;
  }
  
  public Point(Point q)
  { this.x = q.x;
    this.y = q.y;
  }
  
  public Point(double x, double y)
  { this.x = x;
    this.y = y;
  }
  
  public double getX()
  { return x;
  }

  public double getY()
  { return y;
  }

  public Point getLocation()
  { return new Point(x,y);
  }
  public void setLocation(double x, double y)
  { this.x = x;
    this.y = y;
  }

  public double distance(Point point)
  { double dx = this.x - point.x;
    double dy = this.y - point.y;
    return Math.sqrt(dx*dx+dy*dy);
  }
  
  public double magnitude()
  { return distance(ORIGIN);
  }

  public double amplitude()
  { return Math.atan(y/x);
  }
  
  public void setPolar(double r, double theta)
  { this.x = r*Math.cos(theta);
    this.y = r*Math.sin(theta);
  }
  
  public static Point polar(double r, double theta)
  { double x = r*Math.cos(theta);
    double y = r*Math.sin(theta);
    return new Point(x,y);
  }
  
  public void expand(double dr)
  { x *= dr;
    y *= dr;
  }
  
  public void rotate(double theta)
  { double xx = x;
    double yy = y;
    double sin = Math.sin(theta);
    double cos = Math.cos(theta);
    x = xx*cos - yy*sin;
    y = xx*sin + yy*cos;
  }
  
  public void translate(double dx, double dy)
  { x += dx;
    y += dy;
  }

  public boolean equals(Object object)
  { if (object == this) return true;
    if (object.getClass() != this.getClass()) return false;
    Point point = (Point)object;
    return (x == point.x && y == point.y);
  }

  public int hashCode()
  { return (new Double(x)).hashCode() + (new Double(y)).hashCode();
  }

  public String toString()
  { return new String("(" + (float)x + ","  + (float)y + ")");
  }
  
}

