-
Notifications
You must be signed in to change notification settings - Fork 2
/
CoR.java
111 lines (92 loc) · 2.16 KB
/
CoR.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import java.util.*;
class GraphicComposite
{
public String name;
public String color;
public int width;
public int height;
public GraphicGroup children = new GraphicGroup();
public GraphicComposite()
{
}
public void resize(int scale)
{
this.width *= scale;
this.height *= scale;
children.resizeAll(scale);
}
private void print(StringBuilder stringBuilder, int depth)
{
stringBuilder.append(String.join("", Collections.nCopies(depth, "*")))
.append(depth > 0 ? " " : "")
.append((color == null || color.isEmpty()) ? "" : color + " ")
.append((name == null) ? "==GROUP==" : name + " ")
.append((name == null) ? "" : "Width = " + width + " ")
.append((name == null) ? "" : "Height = " + height + " ")
.append(System.lineSeparator());
for (GraphicComposite child : children)
{
child.print(stringBuilder, depth + 1);
}
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
print(sb, 0);
return sb.toString();
}
}
class GraphicGroup extends ArrayList<GraphicComposite>
{
public GraphicGroup()
{
}
public void resizeAll(int scale)
{
for(GraphicComposite g : this)
{
g.resize(scale);
}
}
}
class Oval extends GraphicComposite
{
public Oval(String color, int width, int height)
{
name = "Oval";
this.color = color;
this.width = width;
this.height = height;
}
}
class Rectangle extends GraphicComposite
{
public Rectangle(String color, int width, int height)
{
name = "Rectangle";
this.color = color;
this.width = width;
this.height = height;
}
}
public class CoR
{
public static void main(String[] args)
{
GraphicComposite drawing = new GraphicComposite();
drawing.children.add(new Rectangle("Red", 100, 100));
drawing.children.add(new Oval("Yellow", 200, 200));
GraphicComposite group = new GraphicComposite();
group.children.add(new Oval("Blue", 300, 300));
group.children.add(new Rectangle("Red", 400, 400));
drawing.children.add(group);
System.out.println(drawing);
System.out.println("RESIZE GROUP 4x");
group.resize(2);
System.out.println(drawing);
System.out.println("RESIZE DRAWING 2x");
drawing.resize(2);
System.out.println(drawing);
}
} c