testshape.java

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

JAVA
51
字号
import java.io.*;
import dslib.base.PairUos;

/** A class to test the shape classes at the end of Chapter 6 */
public class TestShape
{
	public static void main(String args[]) throws Exception
	{
		PrintWriter outfile = new PrintWriter(new FileWriter("OutputTestShape.txt"));

		Circle c = new Circle(5);
		Shape temp = c;
		outfile.print(temp);
		Rectangle r = new Rectangle(5, 9);
		temp = r;
		outfile.print(temp);
		Square s = new Square(9);
		temp = s;
		outfile.print(temp);

		c.goPosition(100, 30);
		Figure first = new Figure("first");
		first.insert(c);
		outfile.print(first);

		Figure second = new Figure("second");
		second.insert(c);
		r.goPosition(130, 60);
		second.insert(r);
		second.shift(50, 50);  
		outfile.print(second);

		second.insert(first);  // second now has two references to c, one directly and one via first
		Figure third = new Figure("third");
		third.insert(second);
		first.shift(100, 100);
		third.insert(first);
		third.shift(-200, -200);  // the circle c is shifted three times
		outfile.print(third);

		RotateFigure rf = new RotateFigure("rotatable figure");
		rf.insert(c);
		rf.insert(r);
		rf.insert(s);
		rf.rotate(45);
		outfile.print(rf);

		outfile.close();
	}
}

⌨️ 快捷键说明

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