//• i o/StoreCADState.java
// Сохранение состояния вымышленной системы CAD
import java io *;
import java.util.*:
abstract class Shape implements Serializable {
public static final int RED = 1, BLUE = 2. GREEN = 3: private int xPos, yPos. dimension, private static Random rand = new Random(47), private static int counter = 0; public abstract void setColor(int newColor); public abstract int getColorO; public Shape(int xVal. int yVal, int dim) { xPos = xVal; yPos = yVal; dimension = dim;
}
public String toStringO { return getClassO +
"color[" + getColorO + "] xPos[" + xPos + "] yPos[" + yPos + "] dim[" + dimension + "]\n";
}
public static Shape randomFactory() { int xVal = rand.nextlnt(lOO); int yVal = rand.nextlnt(lOO); int dim = rand.nextlnt(lOO); switch(counter++ % 3) { default:
case 0: return new Circle(xVal. yVal. dim); case 1: return new Square(xVal. yVal, dim); case 2: return new LineCxVal. yVal. dim);
}
class Circle extends Shape {
private static int color = RED;
public CircleCint xVal. int yVal, int dim) {
super(xVal, yVal, dim).
public void setColor(int newColor) { color = newColor. } public int getColorO { return color. }
}
class Square extends Shape { private static int color, public Squared nt xVal. int yVal. int dim) { super(xVal. yVal. dim). color = RED.
}
public void setColor(int newColor) { color = newColor. } public int getColorO { return color. }
}
class Line extends Shape {
private static int color = RED. public static void
serializeStaticState(ObjectOutputStream os) throws IOException { os writelnt(color); } public static void
deserializeStaticState(ObjectInputStream os) throws IOException { color = os.readlntO. } public Line(int xVal. int yVal. int dim) { super(xVal, yVal, dim);
}
public void setColor(int newColor) { color = newColor; } public int getColorO { return color; }