?? figure.java
字號:
import dslib.list.LinkedListUos;
/** A figure with a name and a list of shapes that make up the figure. */
public class Figure extends Shape
{
/** Name of the figure. */
public String name;
/** Set the name to be newName.
Analysis: Time = O(1) */
public void setName(String newName)
{
name = newName;
}
/** The parts of the figure. */
protected LinkedListUos parts;
/** Make a new figure with name newName.
Analysis: Time = O(1) */
public Figure(String newName)
{
name = newName;
parts = new LinkedListUos();
x = 0;
y = 0;
}
/** Add s as a part of the figure.
Analysis: Time = O(1) */
public void insert(Shape s)
{
parts.insertLast(s);
}
/** Shift the position of each part of the figure by shiftX and shiftY.
Analysis: Time = O(number of parts of the figure) */
public void shift(int shiftX, int shiftY)
{
super.shift(shiftX, shiftY);
parts.goFirst();
while (!parts.after())
{
((Shape) parts.item()).shift(shiftX, shiftY);
parts.goForth();
}
}
/** String representation of the figure with indentation for nested parts.
Analysis: Time = O(number of parts to the figure) */
public String toString()
{
String result = "\n" + indent + name + " has parts: ";
indent += " ";
parts.goFirst();
while (!parts.after())
{
result += parts.item();
parts.goForth();
}
indent = indent.substring(0, indent.length() - 5);
return result;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -