point.java

来自「Beginning Java 2, SDK 1.4 Edition Exerci」· Java 代码 · 共 34 行

JAVA
34
字号
// Chapter 6 Exercises 1 & 2

public class Point {
  protected double x = 0.0;
  protected double y = 0.0;

// Constructors:

  public Point(){}

  // Construct a Point from its coordinates:
  public Point(double x, double y) {
    this.x = x;
    this.y = y;
  }

  // Construct a Point from another Point:
  public Point(Point point) {
    x = point.x;
    y = point.y;
  }

  // Method to return a point defined relative to this
  // point in coordinates:
  public Point add(Point z) {
    return new Point(x+z.x,y+z.y);
  }

  // Overrides the method inherited from Object:
  public String toString() {
    return "Point: " + x + "," + y;
  }
}

⌨️ 快捷键说明

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