-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClub.java
328 lines (297 loc) · 9.02 KB
/
Club.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
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
import java.util.ArrayList;
/**
* un Club est une unite qui regroupe tous les elements
* il gere le personnel, prepare au match et ses elements changent selon le resultat
*/
public class Club {
private Manager manager;
private Coach coach;
private ArrayList<Joueur> joueurs;
private ArrayList<Remplacant> remplacants;
private Match match;
private static int annee = 0;
// des valeurs par defaut
private static int nombreJoueurMax = 11;
private static int nombreRemplacantMax = 7;
private static double plafondSalaire = 1000;
private static int anneeMax = 15; // le nombre max d'annee pour evoluer
private static double benefice;
/**
* constructeur avec des param specifiees
* @param manager
* @param coach
* @param joueurs
* @param remplacants
* @param match
*/
public Club(Manager manager, Coach coach, ArrayList<Joueur> joueurs, ArrayList<Remplacant> remplacants,
Match match) {
this.manager = manager;
this.coach = coach;
this.joueurs = joueurs;
this.remplacants = remplacants;
this.match = match;
}
/**
* constructeur par defaut
*/
public Club(){
this.manager = new Manager();
this.coach = new Coach();
this.joueurs = new ArrayList<Joueur>();
this.remplacants = new ArrayList<Remplacant>();
this.match = Match.getMatch(0);
}
/**
* renvoyer les Joueurs et Remplacants de plus de 35 ans en les supprimant
*/
public void renvoyer() {
for(int i = 0; i < joueurs.size(); i++){
Joueur j = joueurs.get(i);
if(j.getAge() >= 38){
joueurs.remove(j);
System.out.println(j + " est renvoye");
i -= 1;
}
}
for(int i = 0; i < remplacants.size(); i++){
Remplacant r = remplacants.get(i);
if(r.getAge() >= 34){
remplacants.remove(r);
System.out.println(r + " est renvoye");
i -= 1;
}
}
}
/***
* avant la promotion, verifie si le salaire total est plus grand que le plafondSalaire
* Si oui, throw new DepassementBudgetException
* sinon, continue
* @return
* @throws DepassementPlafondSalaireException
*/
public boolean budget() throws DepassementPlafondSalaireException{
// a finir
double sumsalaire = manager.salaire + coach.salaire;
for(Joueur j : joueurs){
sumsalaire += j.salaire;
}
for(Remplacant r : remplacants)
{
sumsalaire += r.salaire;
}
if(remplacants.size() == 0){
recrutement();
}
sumsalaire += new Joueur(Outil.remplacantLePlusCapable(remplacants)).getSalaire();
if(sumsalaire <= plafondSalaire){
return true;
}else{
throw new DepassementPlafondSalaireException("Le salaire depasse le plafond.");
}
}
/**
* enlever Le joueur le plus capable de la ArrayList<Joueur>
* pour diminuer le salaire total
*/
public void enleverJoueurLePlusCapable(){
Joueur capmax = Outil.joueurLePlusCapable(joueurs);
System.out.println("le joueur : " + capmax.nom+ " de capacite : " + capmax.capacite + "est enlevee");
joueurs.remove(capmax);
}
/**
* renouveler le contrat pour toute l'equipe
*/
public void renouvelerContrat() {
for (Joueur joueur : joueurs) {
if(joueur.getContrat() == 0)
joueur.setContrat(Joueur.getContratDefaut());
}
for (Remplacant remplacant : remplacants) {
if(remplacant.getContrat() == 0)
remplacant.setContrat(Remplacant.getContratDefaut());
}
}
/**
* trouve un joueur dans la liste de remplacants en le nommant joueur principal
* on peut créer des listes temporaires
*/
public void promotion(){
if(remplacants.size() == 0){
recrutement();
}
Remplacant capmax = remplacants.get(0);
for(Remplacant r : remplacants){
if (capmax.capacite < r.capacite) {
capmax = r;
}
}
joueurs.add(new Joueur(capmax));
System.out.println(capmax + " obtient une promotion.");
remplacants.remove(capmax);
}
/**
* faire decliner tous les joueurs et remplacants
* incrementation d'age et eventuellement diminer la capacite
*/
public void decliner() {
for (Joueur joueur : joueurs) {
joueur.decliner();
}
for (Remplacant remplacant : remplacants) {
remplacant.decliner();
}
}
/***
*completer la liste de remplacants
*/
public void recrutement(){
while(remplacants.size() < nombreRemplacantMax){
remplacants.add(new Remplacant()); //ajouter le joueur recruté
}
}
/**
* renvoie les joueur : age > 30
* promotion
* renouveler les contrats
* recrutement des remplacants
*/
public void mettreAJour(){
decliner();
renvoyer();
renouvelerContrat();
while(joueurs.size() < nombreJoueurMax){
try {
if (budget()) {
promotion();
}
} catch (DepassementPlafondSalaireException e) {
System.out.println(e.getMessage());
enleverJoueurLePlusCapable();
promotion();
}
}
recrutement();
}
/**
* simulation d'un concours de football
* comparer les données du match et la somme de capacite de joueur principaux
* et changer la capacite des joueurs principaux selon l'algorithme ecrit dans Outil.java
*/
public void participerAuMatch(){
this.match = Match.getMatch(getCapaciteNotre());
match.resultMatch();
int nbVictoire = match.getNbVictoire();
int nbDefaite = match.getNbDefaite();
benefice = (Match.beneficeMatch * Manager.addBenefice)*nbVictoire;
coach.setCoachCapaciteMatch(nbVictoire,nbDefaite);
for (Joueur joueur : joueurs) {
int capaciteOriginal = joueur.getCapacite();
joueur.setCapacite(coach.addTeamCapacite+capaciteOriginal + Outil.capaciteDifference(nbVictoire, nbDefaite));
}
match.finirMatch();
annee += 1;
}
/**
* afficher des information pour l'utilisateur
*/
public void sePresenter() {
System.out.println(this.toString());
}
/**
* afficher des information pour l'utilisateur
* version2
*/
public void sePresenter2() {
System.out.println("**********");
System.out.println("**********");
System.out.println("Club de football en fin d'annee " + annee + ".");
manager.sePresenter();
coach.sePresenter();
for (Joueur joueur : joueurs) {
joueur.sePresenter();
}
for (Remplacant remplacant : remplacants) {
remplacant.sePresenter();
}
System.out.println("capacite moyen=" + getCapaciteNotre() + "\n");
System.out.println("benefice du club=" + benefice + "\n");
System.out.println("**********");
System.out.println("**********");
}
/***
* Obtenir la capacite de tous les joueurs principaux
* @return capaciteNotre
*/
public int getCapaciteNotre(){
if(joueurs.size() == 0){
return 0;
}
int capaciteNotre = 0;
for (Joueur joueur : joueurs) {
capaciteNotre += joueur.getCapacite();
}
return capaciteNotre/joueurs.size();
}
@Override
public String toString() {
String str = "**********\n";
str += "**********\n";
str += "Club de football\n";
str += "annee " + annee + "\n";
str += manager.toString() + "\n";
str += coach.toString() + "\n";
for (Joueur joueur : joueurs) {
str += joueur.toString();
}
for (Remplacant remplacant : remplacants) {
str += remplacant.toString();
}
str += "capacite moyen " + getCapaciteNotre() + "\n";
str += "**********\n";
str += "**********\n";
return str;
}
/**
* completer les attributs manquants du Club
*/
public void init() {
if(manager == null){
manager = new Manager();
}
if(coach == null){
coach = new Coach();
}
recrutement();
while(joueurs.size() < nombreJoueurMax){
promotion();
}
recrutement();
if(match == null){
match = Match.getMatch(getCapaciteNotre());
}
}
/**
* faire tourner le Club
*/
public void run() {
while (annee <= anneeMax) {
mettreAJour();
participerAuMatch();
sePresenter2();
}
}
/**
* faire tourner le Club avec un nombre precise d'annees en parametres
*/
public void run(int nbAnnees) {
while (annee <= nbAnnees) {
mettreAJour();
participerAuMatch();
sePresenter2();
}
}
public static void resetAnnee(){
annee = 0;
}
}