// liste des Etudiants inscrits à un cours public List<Etudiant> selectEtudiantsDuCours(Cours cours) // ok { int id, nbrIds; Integer i, k; Etudiant e; List<Integer> idsEleves = new ArrayList<Integer>(); List<Etudiant> etudiantsInscritsCours = new ArrayList<Etudiant>(); // liste des etudiants List<Etudiant> list = this.selectAllEtudiants(); if (cours != null) idsEleves = cours.getIdsEtudiant(); System.out.println("list ids etudiants not null"); nbrIds = cours.getIdsEtudiant().size(); System.out.println("nbr de ids d'etudiant du cours: " + nbrIds); if (idsEleves != null && list != null) { for (Iterator<Integer> j = idsEleves.iterator(); j.hasNext(); ) { k = j.next(); // parcourir liste d'etudiants for (Iterator<Etudiant> iter = list.iterator(); iter.hasNext(); ) { e = iter.next(); id = e.getId(); i = new Integer(id); if (i.equals(k)) etudiantsInscritsCours.add(e); } } } return etudiantsInscritsCours; }
public static void main(String[] args) { Etudiant etudiant1 = new Etudiant("Tourman", "Benjamin", "2 rue Fénélon", 1993); System.out.println("Etudiant n°1 :"); System.out.println("Nom : " + etudiant1.getNom()); System.out.println("Prénom : " + etudiant1.getPrenom()); System.out.println("Adresse : " + etudiant1.getAdresse()); System.out.println("age : " + etudiant1.getAge()); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((etudiant == null) ? 0 : etudiant.hashCode()); result = prime * result + ((module == null) ? 0 : module.hashCode()); result = prime * result + ((prof == null) ? 0 : prof.hashCode()); return result; }
/** * Envoye les valeurs dans la base de données, Ce sont les étudiants avec nom prenom pass * * @author Delaby Pierre * @return rien */ public boolean putVals(GestionEtudiants liste) { // Je crée la requêtes sql String query = "INSERT INTO jeanpier_pv.etudiants_sans_choix VALUES "; int taille = liste.size(); for (int i = 0; i < taille; i++) { Etudiant e = liste.get(i); query += "('" + e.getId() + "', '" + e.getNom() + "', '" + e.getPrenom() + "', '" + e.getPassword() + "')"; // j'ajoute une virgule, sauf à la fin if (i < taille - 1) { query += ","; } } System.out.println(query); // j'exectue la requte try { Statement requete = this.connect.createStatement(); requete.executeUpdate(query); } catch (SQLException sqle) { System.out.println("Erreur à la connexion : " + sqle.getMessage()); } // Fermeture try { if (this.connect != null) this.connect.close(); } catch (SQLException e) { e.printStackTrace(); } return true; }
// liste de Cours inscrits par un Etudiant public ArrayList<Cours> selectCoursInscrits(int idEtudiant) { ArrayList<Cours> listCoursInscrits = new ArrayList<Cours>(); ArrayList<Cours> listCours = this.selectAllCours(); Etudiant etudiant = getEtudiantById(idEtudiant); int[] idsCoursDeEtudiant = etudiant.getIdsCours(); int nbr = idsCoursDeEtudiant.length; if (nbr != 0) { for (int i = 0; i < nbr; i++) { if (listCours != null) // parcourir list de cours for (Iterator<Cours> iter = listCours.iterator(); iter.hasNext(); ) // comparer l'id Cours dans liste de cours et list idsCoursDeEtudiant if (iter.next().getIdCour() == idsCoursDeEtudiant[i]) listCoursInscrits.add(iter.next()); } } return listCoursInscrits; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Enseignement other = (Enseignement) obj; if (etudiant == null) { if (other.etudiant != null) return false; } else if (!etudiant.equals(other.etudiant)) return false; if (module == null) { if (other.module != null) return false; } else if (!module.equals(other.module)) return false; if (prof == null) { if (other.prof != null) return false; } else if (!prof.equals(other.prof)) return false; return true; }
/** * Récupère une liste d'étudiant depuis la base de donéne * * @return la liste de type GestionEtudiants * @author Delaby Pierre */ public GestionEtudiants getValsFromBdd() { GestionEtudiants liste = new GestionEtudiants(); // Récupération des étudiants try { /* * 0 choix pas fais * 1 etud * 2 marche travail * 3 sais pas * * SELECT choix.id_etud, nom_etud, prenom_etud, choix_etud, intitule_form, lieu, priorite * FROM pierdela_java.etudiants, pierdela_java.choix, pierdela_java.formations * WHERE choix.id_etud = etudiants.id_etud * AND formations.id_form = choix.id_form * UNION * SELECT id_etud, nom_etud, prenom_etud, choix_etud, 0, 0, 0 * FROM perdela_java.etudians * WHERE choix_etud = 0 * ORDER BY id_etud, priorite */ Statement requete = this.connect.createStatement(); ResultSet res = requete.executeQuery( "SELECT choix.id_etud, nom_etud, prenom_etud, choix_etud, intitule_form, lieu, priorite FROM jeanpier_pv.etudiants, jeanpier_pv.choix, jeanpier_pv.formations WHERE choix.id_etud = etudiants.id_etud AND formations.id_form = choix.id_form UNION SELECT id_etud, nom_etud, prenom_etud, choix_etud, 0, 0, 0 FROM jeanpier_pv.etudiants WHERE choix_etud != 1 ORDER BY id_etud, priorite"); while (res.next()) { // Opération sur chaque étudiant Etudiant etud = new Etudiant( res.getInt("id_etud"), res.getString("nom_etud"), res.getString("prenom_etud")); // Choix d'orientation Orientation orient; switch (res.getInt("choix_etud")) { case 1: orient = Orientation.poursuite_etude; break; case 2: orient = Orientation.marche_travail; break; case 3: orient = Orientation.sais_pas; break; default: orient = Orientation.pas_choisi; break; } etud.setChoixEtud(orient); // Si l'étudiant n'existe pas, je le crée if (!liste.contains(etud)) liste.add(etud); // Si l'étudiant à choisi une formation, je l'ajoute if (orient == Orientation.poursuite_etude || orient == Orientation.marche_travail) { Formation f = new Formation(res.getString("intitule_form"), res.getString("lieu")); liste.get(liste.indexOf(etud)).addFormation(f); } } } catch (SQLException sqle) { System.out.println("Erreur à la connexion : " + sqle.getMessage()); } // Fermeture try { if (this.connect != null) this.connect.close(); } catch (SQLException e) { e.printStackTrace(); } return liste; }
public Etudiant getEtudiant() { etuAReturn.setCaracteristique(caraAReturn); return etuAReturn; }