TP2: Use a Compactable array for testing purpose.
[TP_POO.git] / TP2 / Main.java
1
2 class Main {
3
4 private static void main1() {
5 Point p1 = new Point(1, 2);
6 Point p2 = new Point(2, 7);
7 Segment segment = new Segment(p1, p2);
8 Point p3 = new Point(4, 5);
9 Cercle cercle = new Cercle(p3, 5.2);
10 Point p4 = new Point(2, 3);
11 Piletransformations trans = new Piletransformations(10);
12
13 boolean rt = trans.empiler(p4);
14 if (!rt) {
15 System.out.println("Echec empilation");
16 }
17
18 segment.dessiner(trans);
19 cercle.dessiner(trans);
20
21 Point p5 = new Point(3, 5);
22 segment.deplacer(p5);
23 cercle.deplacer(p5);
24
25 Image image = new Image();
26 image.ajouter(segment);
27 image.ajouter(cercle);
28 image.dessiner(trans);
29 image.deplacer(p5);
30 image.dessiner(trans);
31
32 trans.depiler();
33 }
34
35 private static void main2() {
36 Point p1 = new Point(1, 2);
37 Point p2 = new Point(2, 7);
38 Segment segment1 = new Segment(p1, p2);
39 Point p3 = new Point(1, 5);
40 Point p4 = new Point(3, 1);
41 Segment segment2 = new Segment(p3, p4);
42 Point p5 = new Point(4, 5);
43 Cercle cercle1 = new Cercle(p5, 5.2);
44 Point p6 = new Point(5, 4);
45 Cercle cercle2 = new Cercle(p6, 4.3);
46 Point point1 = new Point(8, -1.5);
47 Image image1 = new Image();
48 Image image2 = new Image();
49 Image image3 = new Image();
50 Piletransformations transformations = new Piletransformations(10);
51
52 transformations.empiler(point1);
53 image1.ajouter(segment1);
54 image1.ajouter(cercle1);
55 image2.ajouter(segment2);
56 image2.ajouter(cercle2);
57 image1.dessiner(transformations);
58 image2.dessiner(transformations);
59 Point point2 = new Point(0.5, 2.5);
60 image1.deplacer(point2);
61 image3.ajouter(image1);
62 image3.ajouter(image2);
63 image3.dessiner(transformations);
64 transformations.depiler();
65 }
66
67 public static void main3() {
68
69 Affichable[] affichable = new Affichable[10];
70
71 Point p1 = new Point(1, 2);
72 Point p2 = new Point(2, 7);
73 Point p3 = new Point(1, 5);
74
75 Entiers entiers = new Entiers(5);
76 entiers.inserer(3);
77 entiers.inserer(1);
78 entiers.inserer(5);
79
80 Liste liste = new Liste();
81 liste.inserer(3);
82 liste.inserer(1);
83 liste.inserer(5);
84
85 for (int i = 0; i < 10; i++) {
86 affichable[i] = entiers;
87 affichable[i].afficher();
88
89 affichable[i] = liste;
90 affichable[i].afficher();
91
92 affichable[i] = new Segment(p1, p2);
93 affichable[i].afficher();
94
95 affichable[i] = new Cercle(p3, 5.5);
96 affichable[i].afficher();
97 }
98
99 }
100
101 public static void main4() {
102
103 Compactable[] compactable = new Compactable[10];
104
105 Point p1 = new Point(1, 2);
106 Point p2 = new Point(2, 7);
107 Point p3 = new Point(1, 5);
108 Point p4 = new Point(3, 1);
109
110 Segment segment1 = new Segment(p1, p2);
111 Segment segment2 = new Segment(p3, p4);
112 Cercle cercle = new Cercle(p3, 5.5);
113 Image image = new Image();
114 image.ajouter(segment1);
115 image.ajouter(segment2);
116 image.ajouter(cercle);
117
118 Entiers entiers = new Entiers(5);
119 entiers.inserer(3);
120 entiers.inserer(1);
121 entiers.inserer(4);
122
123 Liste liste = new Liste();
124 liste.inserer(3);
125 liste.inserer(1);
126 liste.inserer(5);
127 liste.inserer(4);
128
129 compactable[0] = entiers;
130 entiers.afficher();
131 compactable[0].compacter(1);
132 entiers.afficher();
133
134 compactable[1] = liste;
135 liste.afficher();
136 compactable[1].compacter(1);
137 liste.afficher();
138
139 compactable[2] = image;
140 image.afficher();
141 compactable[2].compacter(1);
142 image.afficher();
143 }
144
145 public static void main(String[] args) {
146
147 main4();
148
149 }
150
151 }