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

📄 point.java

📁 Java2入门经典第五章源码
💻 JAVA
字号:
package Geometry;

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

  // Create a Point from an existing Point object
  public Point(final Point aPoint)
  {
    x = aPoint.x;
    y = aPoint.y;
  }

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

  // Calculate the distance to another point
  public 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"
  }

  // Retrieve the x coordinate
  public double getX()
  { return x;  }

  // Retrieve the y coordinate
  public double getY()
  { return y;  }

  // Set the x coordinate
  public void setX(double inputX)
  { x = inputX;  }

  // Set the y coordinate
  public void setY(double inputY)
  { y = inputY;  }

  // Coordinates of the point
  private double x;
  private double y;
}

⌨️ 快捷键说明

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