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

📄 line.java

📁 JAVA 2入门经典 练习答案
💻 JAVA
字号:
// Chapter 6 Exercise 3

// This class now inherits implementation of the ShapeInterface
// interface so it must implement the show() method, otherwise
// it would be and abstract class.

public class Line extends Shape {
  // End point is defined relative to start point:
  private Point end;                    // Line end point.

// Constructor:
  public Line(Point start, Point end) {
    // Assume line is drawn from reference point:
    position = new Point(start);	                  // First point is position.
    this.end = new Point(end.x-start.x, end.y - start.y); // Get end point coords relative to start. 
  }

  // Overrides the method inherited from Object:
  public String toString()  {  
    // Create a string representation of the object:
    return "Line: " + position + " to " + position.add(end);
  }

  // Method to display a line:
  public void show() {
    System.out.println("\n"+toString());
  }
}

⌨️ 快捷键说明

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