-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCentreTri.java
More file actions
220 lines (181 loc) · 7.63 KB
/
Copy pathCentreTri.java
File metadata and controls
220 lines (181 loc) · 7.63 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import dechets.*;
import utile.AttXML;
import utile.EcritureFichier;
import vaisseaux.Vaisseaux;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
/**
* Created by DioAn1730700 on 2018-04-26.
*/
public class CentreTri implements Serializable{
protected int matrecyclage;
protected Queue<Vaisseaux> attente = new LinkedList<>();
protected Stack<Dechets> pileNep = new Stack<>();
protected Stack<Dechets> pilePluto = new Stack<>();
protected Stack<Dechets> pileTerbi = new Stack<>();
protected Stack<Dechets> pileThul = new Stack<>();
protected Stack<Dechets> pileGado = new Stack<>();
protected String nom;
//à changer au besoin
public static int attenteMax = 5;
public Stack<Dechets> getPileNep() {
return pileNep;
}
public void setPileNep(Stack<Dechets> pileNep) {
this.pileNep = pileNep;
}
public Stack<Dechets> getPilePluto() {
return pilePluto;
}
public void setPilePluto(Stack<Dechets> pilePluto) {
this.pilePluto = pilePluto;
}
public Stack<Dechets> getPileTerbi() {
return pileTerbi;
}
public void setPileTerbi(Stack<Dechets> pileTerbi) {
this.pileTerbi = pileTerbi;
}
public Stack<Dechets> getPileThul() {
return pileThul;
}
public void setPileThul(Stack<Dechets> pileThul) {
this.pileThul = pileThul;
}
public Stack<Dechets> getPileGado() {
return pileGado;
}
public void setPileGado(Stack<Dechets> pileGado) {
this.pileGado = pileGado;
}
public Queue<Vaisseaux> getAttente() {return attente;}
public void setAttente(Queue<Vaisseaux> attente) {this.attente = attente;}
public CentreTri(String nom) {
this.nom = nom;
}
public int getMatrecyclage() {
return matrecyclage;
}
public void setMatrecyclage(int matrecyclage) {
this.matrecyclage = matrecyclage;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public static boolean neptu = true;
public static boolean pluto = true;
public static boolean gado = true;
public static boolean terbi = true;
public static boolean thuli = true;
public static boolean exception = true;
public void déchargeDechets(Vaisseaux vaisseaux)
throws Exceptions.ListeVideCentreTris, Exceptions.DernierCentreTris, Exceptions.CentreTrisPlein{
//à changer au besoin
int nbMax = 1000;
for(int i = 0; i < vaisseaux.getMatiere().size(); i++){
if (vaisseaux.getMatiere().get(i).getType().equals("Gadolinium") && gado == true){
if (pileGado.size()<nbMax){
pileGado.add(new Gadolinium());
}
else {
EcritureFichier.affichageSimulation("La pile de Gadolinium est pleine");
gado = false;
if (attente.size() == 0) {
throw new Exceptions.ListeVideCentreTris();
}
else {
recycler(pileGado, AttXML.getGadoRecyc(), attente.poll());
} } }
else if (vaisseaux.getMatiere().get(i).getType().equals("Neptunium") && neptu== true){
if (pileNep.size()<nbMax){
pileNep.add(new Neptunium());
}else {
EcritureFichier.affichageSimulation("La pile de Neptunium est pleine");
neptu = false;
if (attente.size() == 0) {
throw new Exceptions.ListeVideCentreTris();
}
else {
recycler(pileNep, AttXML.getNeptuRecyc(), attente.poll());
} } }
else if (vaisseaux.getMatiere().get(i).getType().equals("Plutonium") && pluto == true){
if (pilePluto.size()<nbMax){
pilePluto.add(new Plutonium());
}
else {
EcritureFichier.affichageSimulation("La pile de Plutonium est pleine");
pluto =false;
if (attente.size() == 0) {
throw new Exceptions.ListeVideCentreTris();
}
else {
recycler(pilePluto, AttXML.getPlutoRecyc(), attente.poll());
} } }
else if (vaisseaux.getMatiere().get(i).getType().equals("Terbium") && terbi == true){
if (pileTerbi.size()<nbMax){
pileTerbi.add(new Terbium());
}
else {
EcritureFichier.affichageSimulation("La pile de Terbium est pleine");
terbi = false;
if (attente.size() == 0) {
throw new Exceptions.ListeVideCentreTris();
}
else {
recycler(pileTerbi, AttXML.getTerbiRecyc(), attente.poll());
} } }
else if (vaisseaux.getMatiere().get(i).getType().equals("Thulium") && thuli == true){
if (pileThul.size()<nbMax){
pileThul.add(new Thulium());
}
else {
EcritureFichier.affichageSimulation("La pile de Thulium est pleine");
thuli = false;
if (attente.size() == 0) {
throw new Exceptions.ListeVideCentreTris();
}
else {
recycler(pileThul, AttXML.getThuliRecyc(), attente.poll());
} } }
if (i == (vaisseaux.getMatiere().size()-1)){
vaisseaux.decharger();
if (attente.size() == attenteMax){
attente.peek().setCentreActu(attente.peek().getCentreActu() + 1);
EcritureFichier.affichageSimulation("Vaisseau de la liste d'attente envoyé sur une nouvelle planète");
EcritureFichier.affichageSimulation("\n");
Simulation.envoie(attente.poll());
attente.add(vaisseaux);
} else {
attente.add(vaisseaux);
}
}
}
}
public void recycler(Stack<Dechets> p, int recyc, Vaisseaux vaisseaux)
throws Exceptions.DernierCentreTris, Exceptions.ListeVideCentreTris, Exceptions.CentreTrisPlein{
EcritureFichier.affichageSimulation("Appel d'un vaisseau en attente: " + vaisseaux.getNom());
EcritureFichier.affichageSimulation("\n");
int pourcentage = (((recyc*p.size())/100));
for (int i=0; i<pourcentage; i++){
vaisseaux.getMatiere().add(p.pop());
}
vaisseaux.setCentreActu(vaisseaux.getCentreActu()+1);
Simulation.envoieRecyclage(vaisseaux);
}
public void afficher(){
EcritureFichier.affichageSimulation("Vaisseaux en attente d'un départ : " + attente.size());
EcritureFichier.affichageSimulation(nom);
EcritureFichier.affichageSimulation(pileGado.size() + " Gadolinium");
EcritureFichier.affichageSimulation(pileNep.size() + " Neptunium");
EcritureFichier.affichageSimulation(pilePluto.size() + " Plutonium");
EcritureFichier.affichageSimulation(pileTerbi.size() + " Terbium");
EcritureFichier.affichageSimulation(pileThul.size() + " Thulium");
EcritureFichier.affichageSimulation("\n");
EcritureFichier.affichageSimulation("--------------------");
}
}