From 9fe033ea88c2f705ec18c232873d056e0c229d72 Mon Sep 17 00:00:00 2001 From: Gaspard Coulet Date: Wed, 28 Apr 2021 23:05:53 +0200 Subject: Initial commit --- .../Cours406/src/tp2/Etudiant.java | 118 +++++++++++++++++++++ .../Cours406/src/tp2/Gestion.java | 29 +++++ .../eclipse-workspace/Cours406/src/tp2/Main.java | 23 ++++ .../Cours406/src/tp2/NameGenerator.java | 27 +++++ .../Cours406/src/tp2/Promotion.java | 85 +++++++++++++++ 5 files changed, 282 insertions(+) create mode 100644 sem_4/java/eclipse-workspace/Cours406/src/tp2/Etudiant.java create mode 100644 sem_4/java/eclipse-workspace/Cours406/src/tp2/Gestion.java create mode 100644 sem_4/java/eclipse-workspace/Cours406/src/tp2/Main.java create mode 100644 sem_4/java/eclipse-workspace/Cours406/src/tp2/NameGenerator.java create mode 100644 sem_4/java/eclipse-workspace/Cours406/src/tp2/Promotion.java (limited to 'sem_4/java/eclipse-workspace/Cours406/src/tp2') diff --git a/sem_4/java/eclipse-workspace/Cours406/src/tp2/Etudiant.java b/sem_4/java/eclipse-workspace/Cours406/src/tp2/Etudiant.java new file mode 100644 index 0000000..ca78a4b --- /dev/null +++ b/sem_4/java/eclipse-workspace/Cours406/src/tp2/Etudiant.java @@ -0,0 +1,118 @@ +package tp2; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.text.DateFormat; +import java.text.ParseException; + +public class Etudiant { + private String nom; + private Date birthdate; + private int codeIns; + private int codePays; + private double note1; + private double note2; + private double note3; + public Etudiant() { + nom = "None"; + } + public String getNom() { + return nom; + } + public void setNom(String nom) { + this.nom = nom; + } +// public int getAge() throws ParseException { +// return 2018-; +// } + public Date getBirthYear() { + return birthdate; + } + public void setBirthyear(Date birthyear) { + this.birthdate = birthyear; + } + public int getCodeIns() { + return codeIns; + } + public void setCodeIns(int codeIns) { + this.codeIns = codeIns; + } + public int getCodePays() { + return codePays; + } + public void setCodePays(int codePays) { + this.codePays = codePays; + } + public double getNote1() { + return note1; + } + public void setNote1(double note1) { + this.note1 = note1; + } + public double getNote2() { + return note2; + } + public void setNote2(double note2) { + this.note2 = note2; + } + public double getNote3() { + return note3; + } + public void setNote3(double note3) { + this.note3 = note3; + } + public Etudiant(String name, /*Date birthyear,*/ int codeIns, int codePays, double note1, double note2, double note3) { + super(); + this.nom=name; +// this.birthdate = birthyear; + this.codeIns = codeIns; + this.codePays = codePays; + this.note1 = note1; + this.note2 = note2; + this.note3 = note3; + } + public double getMoy() { + return (note1+note2+note3)/3; + } + public String getMention() { + double moy = getMoy(); + if ( moy > 10) { + if (moy < 12) { + return "Admis"; + } + else if (moy < 14) { + return "Assez bien"; + } + else if (moy < 16) { + return "Bien"; + } + else { + return "Très bien"; + } + } + else { + return "Ajourné"; + } + } + public void ligneResultats (){ + String tmp = getMention(); + String ret = getNom()+" "+ getBirthYear()+" "+(int)(getMoy()*100)/100.+" "+tmp+" "; + if (tmp.equals("Ajourné")) { + if ( note1>=10 ) { + ret+="module 1 acquis "; + } + if ( note2>=10 ) { + ret+="module 2 acquis "; + } + if ( note3>=10 ) { + ret+="module 3 acquis "; + } + } + System.out.println(ret); + } + public String toString() { + String ret = "Nom : "+getNom()+"\n"+/*"Age : "+getAge()+"\n"+*/"Année de naissance : "+getBirthYear()+"\n"+"Premiere inscription ? " +(getCodeIns()==0?"Oui":"Non")+"\n"+ "Nationalité : "+ (getCodePays()==0? "Francaise": (getCodePays()==1? "Autre francophone":"Autre non-francophone"))+ "\n"+"Notes : "+ (int)(getNote1()*100)/100.+" "+ (int)(getNote2()*100)/100.+" "+(int)(getNote3()*100)/100.+"\n"+"Moyenne : "+(int)(getMoy()*100)/100.+" "+getMention()+"\n"; + return ret; + } +} + diff --git a/sem_4/java/eclipse-workspace/Cours406/src/tp2/Gestion.java b/sem_4/java/eclipse-workspace/Cours406/src/tp2/Gestion.java new file mode 100644 index 0000000..01a6da9 --- /dev/null +++ b/sem_4/java/eclipse-workspace/Cours406/src/tp2/Gestion.java @@ -0,0 +1,29 @@ +package tp2; +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; +import java.text.DateFormat; +import java.text.ParseException; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +public class Gestion { + + public static void mainzbeb(String[] args) throws Exception { + Etudiant[] groupe=new Etudiant[150]; + String string = "January 2, 2010"; + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM d, yyyy", Locale.ENGLISH); + LocalDate date = LocalDate.parse(string, formatter); + + //Date d=df.parse(test); + for (int i=0; i < 150; i ++) { + groupe[i]=new Etudiant(NameGenerator.generateName()+" "+NameGenerator.generateName(),/*date,*/ (int)(Math.random()*(2-0)),(int)(Math.random()*(4-0)),(double)(Math.random()*(21-0)),(double)(Math.random()*(21-0)),(double)(Math.random()*(21-0))); + //groupe[i].ligneResultats(); + System.out.println(groupe[i].toString()); + } + + + + + } + +} diff --git a/sem_4/java/eclipse-workspace/Cours406/src/tp2/Main.java b/sem_4/java/eclipse-workspace/Cours406/src/tp2/Main.java new file mode 100644 index 0000000..bbafbcc --- /dev/null +++ b/sem_4/java/eclipse-workspace/Cours406/src/tp2/Main.java @@ -0,0 +1,23 @@ +package tp2; + +import java.util.ArrayList; + +public class Main { + + public static void main(String[] args) { + int nbetu= 20000; + Promotion prom = new Promotion(2017); + for ( int i = 0; i < nbetu; i ++) { + prom.Inscrire(NameGenerator.generateName()+" "+NameGenerator.generateName(),/*date,*/ (int)(Math.random()*(1-0)),(int)(Math.random()*(3-0)),(double)(Math.random()*(20-0)),(double)(Math.random()*(20-0)),(double)(Math.random()*(20-0))); + } + ArrayList nofranco = prom.nouveauxInscritsNonFrancophones(); + for (int i = 0 ; i < nofranco.size(); i ++) { + System.out.println(nofranco.get(i).toString()); + } + ArrayList boss = prom.majors(); + for (int i = 0 ; i < boss.size(); i ++) { + System.out.println(boss.get(i).toString()); + } + } + +} diff --git a/sem_4/java/eclipse-workspace/Cours406/src/tp2/NameGenerator.java b/sem_4/java/eclipse-workspace/Cours406/src/tp2/NameGenerator.java new file mode 100644 index 0000000..35bb016 --- /dev/null +++ b/sem_4/java/eclipse-workspace/Cours406/src/tp2/NameGenerator.java @@ -0,0 +1,27 @@ +package tp2; + +import java.util.Random; + +public class NameGenerator { + + private static String[] Beginning = { "Kr", "Ca", "Ra", "Mrok", "Cru", + "Ray", "Bre", "Zed", "Drak", "Mor", "Jag", "Mer", "Jar", "Mjol", + "Zork", "Mad", "Cry", "Zur", "Creo", "Azak", "Azur", "Rei", "Cro", + "Mar", "Luk" }; + private static String[] Middle = { "air", "ir", "mi", "sor", "mee", "clo", + "red", "cra", "ark", "arc", "miri", "lori", "cres", "mur", "zer", + "marac", "zoir", "slamar", "salmar", "urak" }; + private static String[] End = { "d", "ed", "ark", "arc", "es", "er", "der", + "tron", "med", "ure", "zur", "cred", "mur" }; + + private static Random rand = new Random(); + + public static String generateName() { + + return Beginning[rand.nextInt(Beginning.length)] + + Middle[rand.nextInt(Middle.length)]+ + End[rand.nextInt(End.length)]; + + } + + } \ No newline at end of file diff --git a/sem_4/java/eclipse-workspace/Cours406/src/tp2/Promotion.java b/sem_4/java/eclipse-workspace/Cours406/src/tp2/Promotion.java new file mode 100644 index 0000000..6fe7d45 --- /dev/null +++ b/sem_4/java/eclipse-workspace/Cours406/src/tp2/Promotion.java @@ -0,0 +1,85 @@ +package tp2; + +import java.util.ArrayList; +public class Promotion { + private ArrayList listeetudiants; + private int annee; + public Promotion () { + + } + public Promotion (int ext_annee) { + listeetudiants= new ArrayList (); + annee = ext_annee; + } + public int getNbEtu() { + return listeetudiants.size(); + } + public Etudiant getEtu(int n) { + return listeetudiants.get(n); + } + public void Inscrire (String name, /*Date birthyear,*/ int codeIns, int codePays, double note1, double note2, double note3) { + listeetudiants.add(new Etudiant(name,codeIns,codePays,note1, note2, note3)); + } + public double moyenneGenerale () { + double totnotes =0; + for (int i =0; i < this.getNbEtu();i ++ ) { + totnotes += listeetudiants.get(i).getMoy(); + } + if (getNbEtu()!=0) { + return totnotes/this.getNbEtu(); + } + else return -1; + } + public void afficheRes () { + for (int i =0 ; i < this.getNbEtu();i++) { + listeetudiants.get(i).ligneResultats(); + } + } + public Etudiant recherche( String name) { + Etudiant ret= new Etudiant(); + for (int i =0 ; i < this.getNbEtu();i++) { + if ( listeetudiants.get(i).getNom() == name) { + ret = listeetudiants.get(i); + } + + } + return ret; + } + public ArrayList admis () { + ArrayList ret = new ArrayList(); + for ( int i =0; i < this.getNbEtu(); i ++) { + if ( listeetudiants.get(i).getMoy()>=10) { + ret.add(listeetudiants.get(i)); + } + } + return ret; + } + public ArrayList nouveauxInscritsNonFrancophones() { + ArrayList ret = new ArrayList(); + for ( int i =0; i < this.getNbEtu(); i ++) { + if ( listeetudiants.get(i).getCodeIns()==0) { + if ( listeetudiants.get(i).getCodePays()==2) { + ret.add(listeetudiants.get(i)); + } + } + } + return ret; + } + public ArrayList majors() { + ArrayList ret = new ArrayList(); + double maxmoy = 0; + for (int i =0; i < this.getNbEtu();i++) { + if ( listeetudiants.get(i).getMoy() > maxmoy) { + maxmoy = listeetudiants.get(i).getMoy(); + } + } + for (int i =0; i < this.getNbEtu();i++) { + if ( listeetudiants.get(i).getMoy() == maxmoy) { + ret.add(listeetudiants.get(i)); + } + } + return ret; + + + } +} -- cgit v1.2.3