rotatefigure.java
来自「国外的数据结构与算法分析用书」· Java 代码 · 共 40 行
JAVA
40 行
import dslib.exception.*;
/** A Figure with rotation capabilities */
public class RotateFigure extends Figure
{
/** Constructor for the rotating figure
Analysis : Time = O(1) */
public RotateFigure(String x)
{
super(x);
}
/** Rotate the figure deg degrees counter-clockwise.
Analysis: time = O(number of parts to the figure) */
public void rotate(int deg)
{
parts.goFirst();
while (!parts.after())
{
Shape item = (Shape) parts.item();
if (item instanceof Rectangle)
{
Rectangle c = (Rectangle)item;
/* Code to rotate a rectangle. */
}
else if (item instanceof Circle)
{
Circle r = (Circle)item;
/* Code to rotate a circle. */
}
else if (item instanceof Square)
{
Square s = (Square)item;
/* Code to rotate a square. */
}
parts.goForth();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?