line.java

来自「国外的数据结构与算法分析用书」· Java 代码 · 共 35 行

JAVA
35
字号
import dslib.base.PairUos;

/**	A line with a length and slope, and also x and y coordinates (inherited from Shape). */
public class Line extends Shape
{
	/**	length and slope of the line */
	protected int length, slope;
	
	/**	Create a Line with length newLength and slope newSlope, and positioned at (0,0)
		Analysis: Time = O(1) */
	public Line(int newLength, int newSlope)
	{
		length = newLength;
		slope = newSlope;
		x = 0;
		y = 0;
	}

	/**	Set the length and slope to newLength and newSlope 
		Analysis: Time = O(1) */
	public void setDimensions(int newLength, int newSlope)
	{
		length = newLength;
		slope = newSlope;
	}	
   
	/**	String representation of the line 
		Analysis: Time = O(1) */
	public String toString()   
	{
		return "\n" + indent + "Line with length " + length + " and slope " + slope + " degrees" 
				+ "\n" + super.toString();
	}
}

⌨️ 快捷键说明

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