Bonjour,
Voici mon programme,
Code java : Sélectionner tout - Visualiser dans une fenêtre à part
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160 import java.util.*; public class Spot { private String marque; private Led[]tabLed; private Timer timer; private final int tension = 220; private final int minLed = 3; private final int maxLed = 20; public String getMarque() { return this.marque; } public Timer getTimer() { return this.timer; } public Spot(String marque, Led[]l, Timer timer) { this.marque = marque; this.timer = timer; if(l.length > 2 && l.length < 21) { this.tabLed = l; } else if(l.length > 20) { this.tabLed = new Led[20]; } else if(l.length < 3) { this.tabLed = new Led[3]; } else { int i2 = 0; for(int i = 0; i < l.length; i++) { this.tabLed[i] = l[i]; i2++; } for(int i = i2; i < 3; i++) { this.tabLed[i] = new Led(); } } } public Spot() { this.tabLed = new Led[3]; this.timer = new Timer(); } public Spot(Spot s) { this.marque = s.getMarque(); this.timer = s.getTimer(); this.tabLed = new Led[s.tabLed.length]; for (int i = 0; i < s.tabLed.length; i++) { this.tabLed[i] = s.tabLed[i]; } } public void allumer() { for(int i = 0; i < this.tabLed.length; i++) { this.tabLed[i].allumer(); } } public void eteindre() { for(int i = 0; i < this.tabLed.length; i++) { this.tabLed[i].eteindre(); } } public void clignoter() { for(int i = 0; i < this.tabLed.length; i++) { this.tabLed[i].clignoter(); } } public void cycle(int nB) { this.timer.activer(); for(int j = 0; j < nB; j++) { for(int i = 0; i < this.tabLed.length; i++) { this.tabLed[i].clignoter(); System.out.println(this); this.timer.utiliser(); } } this.timer.desactiver(); } public void init() { Scanner input = new Scanner(System.in); System.out.println("Marque du Spot?"); this.marque = input.nextLine(); this.timer = new Timer(); this.timer.init(); int n = 0; System.out.println("Nombre de leds?"); n = input.nextInt(); this.tabLed = new Led[n]; for(int i = 0; i < n; i++) { this.tabLed[i] = new Led(); this.tabLed[i].init(); } } public String toString() { String s = this.getMarque(); for(int i = 0; i < this.tabLed.length; i++) { s = s + tabLed[i]; } return s; } }
Mon programme test,
Code java : Sélectionner tout - Visualiser dans une fenêtre à part
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 public class TestSpot { public static void main(String[]args) { Spot spot = new Spot(); spot.toString(); spot.init(); spot.toString(); Led[] l = { new Led(1234, true), new Led(4567, false), new Led(8910, true)}; Led[] tabLed = new Led[5]; Spot spot1 = new Spot("Strumpfel", tabLed, 2000); spot1.cycle(3); spot1.eteindre(); Spot spot2 = new Spot(spot1); spot1.allumer(); spot1.toString(); spot2.toString(); } }
Mon erreur de compilation est la suivante,
TestSpot.java:15: cannot find symbol
symbol : constructor Spot(java.lang.String,Led[],int)
location: class Spot
Spot spot1 = new Spot("Strumpfel", tabLed, 2000);
^
1 error
Une idée?
Partager