JAVA : Solution EdL #1
public static void lancerPrgm(int x) {
for (int i = 1; i < x; i++)
System.out.println(genEleve().decrire());
}
public static Eleve genEleve() {
Random alea = new Random();
int n = alea.nextInt(11)+4, i = 0;
String nom = "", prenom = "";
for (; i < n; i++)
nom += (char)(byte)(alea.nextInt(26)+65);
n = alea.nextInt(6)+4;
for (i = 0; i < n; i++)
prenom += (char)(byte)(alea.nextInt(26)+97);
float[] notes = new float[5];
for (i = 0; i < 5; i++)
notes[i] = alea.nextInt(21);
return new Eleve(nom, prenom, notes);
}
public class Eleve {
private String nom = "DEFAULT", prenom = "default";
private float[] notes = {0,0,0,0,0};
public Eleve(String aNom, String aPrenom, float[] aNotes) {
this.nom = aNom;
this.prenom = aPrenom;
for (int i = 0; i < 5; i++) {
float n = aNotes[i];
if (n < 21 && n > -1)
this.notes[i] = n;
}
}
public Eleve() {}
public String decrire() {
String tmp = this.notes[0]+", "+this.notes[1]+", "+this.notes[2]+", "+this.notes[3]+" et "+this.notes[4];
return this.prenom+' '+this.nom+" a pour notes "+tmp;
}
}