-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGestion.java
186 lines (163 loc) · 4.49 KB
/
Gestion.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
import java.io.*;
import java.util.*;
public class Gestion
{
public static int saisie_num()
{
try{
BufferedReader buff = new BufferedReader (new InputStreamReader(System.in));
String chaine=buff.readLine();
int num = Integer.parseInt(chaine);
return num;
}
catch(IOException e) {return 0;}
}
public static float saisie_float()
{
try{
BufferedReader buff = new BufferedReader (new InputStreamReader(System.in));
String chaine=buff.readLine();
float f = Float.parseFloat(chaine);
return f;
}
catch(IOException e) {return 0;}
}
/**
Saisie d'une chaine de caracteres
**/
public static String saisie_chaine()
{
try{
BufferedReader buff = new BufferedReader (new InputStreamReader(System.in)); // on atteint buffreader a partir de sys.in
String chaine=buff.readLine();
return chaine;
}
catch(IOException e) {System.out.println(" impossible"+e);
return null;
}
}
public static void main(String[] argv)
{
Protocole protocole = new Protocole(); //possibilité de crééer plusieurs protocoles, si on rajoute des paramètres dans le constructeur
ArrayList animaux = new ArrayList();
int jour = 0;
ArrayList<String> especes = protocole.getEspeces();
Hashtable tests_dispos = protocole.getTestsDispos();
List<String> semaine = protocole.getSemaine();
saisie_animaux(animaux,especes);
for(Iterator<String> e = semaine.iterator();e.hasNext();)
{
System.out.println("Nouveau jour");
saisie_resultats(animaux, tests_dispos, semaine, jour);
//sauvegarde_resultats
}
System.out.println("Fin de la semaine");
}
public static int saisie_resultats(ArrayList animaux, Hashtable ht, List<String> semaine, int jour)
{
for (int i=0;i<animaux.size();i++)
{
Animal animal = (Animal)animaux.get(i);
System.out.println("Taper o si l'animal est mort");
String reponse = saisie_chaine();
if (!reponse.equals("o"))
{
int resultat_courant = animal.getResultat();
int resultat = 0;
System.out.println("Donnez le poids de l'animal "+animal.getId()+" :");
float poids = saisie_float();
animal.setPoids(poids);
ArrayList<String> tests = trouver_tests(animal, ht);
for (String test : tests)
{
switch (test)
{
case "Labyrinthe":
{
Labyrinthe lab = new Labyrinthe();
lab.saisie_utilisateur();
resultat=lab.getTemps();
break;
}
case "Nourriture":
{
Nourriture nour = new Nourriture();
nour.saisie_utilisateur();
resultat=nour.getNbEchecs();
break;
}
case "Image":
{
Image img = new Image();
img.saisie_utilisateur();
resultat=img.getNbEchecs();
break;
}
}
}
animal.setResultat(resultat);
if (semaine.get(jour) == semaine.get(0))
animal.setPoidsDebutSemaine(poids);
else
animal.setProgression(resultat_courant);
System.out.println();
}
//else
//retirer animal de laliste
}
jour++;
return jour;
}
public static ArrayList<String> trouver_tests(Animal animal, Hashtable ht)
{
Enumeration pops = ht.keys();
ArrayList<String> tests = new ArrayList<String>();
while(pops.hasMoreElements())
{
String pop = (String)pops.nextElement();
if (pop == animal.getPop())
tests = (ArrayList<String>)ht.get(pop);
}
return tests;
}
public static void saisie_animaux(ArrayList animaux, ArrayList especes)
{
for (int i=0;i<especes.size();i++)
{
String espece = (String)especes.get(i);
saisie_animaux_type(animaux,espece);
}
}
public static void saisie_animaux_type(ArrayList animaux, String espece)
{
System.out.println("Nombre d'animaux de type "+espece+" a saisir ?");
int nb = saisie_num();
for (int i=0;i<nb;i++)
{
System.out.println();
System.out.println("Sexe ?");
String sexe = saisie_chaine();
System.out.println("Poids ?");
float poids = saisie_float();
switch (espece) // a modifier si ajout d'autres especes
{
case "souris":
{
System.out.println("Groupe ?");
int groupe = saisie_num();
System.out.println();
Souris souris = new Souris(sexe, poids, groupe);
animaux.add(souris);
break;
}
case "singe":
{
System.out.println();
Singe singe = new Singe(sexe, poids);
animaux.add(singe);
break;
}
}
}
}
}