⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 point.java

📁 Java2入门经典第五章源码
💻 JAVA
字号:
class Point
{
  // Coordinates of the point
  double x;
  double y;

  // Create a point from coordinates
  Point(double xVal, double yVal)
  {
    x = xVal;
    y = yVal;
  }

  // Create a point from another Point object
  Point(final Point oldPoint)
  {
    x = oldPoint.x;    // Copy x coordinate
    y = oldPoint.y;    // Copy y coordinate
  }

  // Move a point
  void move(double xDelta, double yDelta)
  {
    // Parameter values are increments to the current coordinates
    x += xDelta;
    y += yDelta;
  }

  // Calculate the distance to another point
  double distance(final Point aPoint)
  {
    return Math.sqrt( 
       (x - aPoint.x)*(x - aPoint.x) + (y - aPoint.y)*(y - aPoint.y) );
  }

  // Convert a point to a string 
  public String toString()
  {
    return Double.toString(x) + ", " + y;    // As "x, y"
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -