commit bc2d9723d22e543d6fb3ae3c413b4f941ba7a50b Author: Marc Date: Tue Oct 7 16:41:03 2025 +0200 tp2correction diff --git a/Amphi.java b/Amphi.java new file mode 100644 index 0000000..dbfc363 --- /dev/null +++ b/Amphi.java @@ -0,0 +1,35 @@ +package lepack; + +import java.util.ArrayList; + +public class Amphi extends Salle { + + private int hauteurSousPlafond; + private boolean regie; + private ArrayList sallesVoisines; + + public Amphi(String numSalle, int ht, boolean aUneRegie) { + super(numSalle); + this.hauteurSousPlafond = ht; + this.regie = aUneRegie; + this.sallesVoisines = new ArrayList<>(); + } + + @Override + public void afficherInfos() { + System.out.println("\n-> Amphithéâtre numero : " + getNumero()); + System.out.println(" Hauteur : " + hauteurSousPlafond + "m, Régie : " + (regie ? "Oui" : "Non")); + + if (getListeOuvertures().isEmpty()) { + System.out.println(" Aucune ouverture."); + } else { + for (Ouverture ouv : getListeOuvertures()) { + ouv.afficherInfos(); + } + } + } + + public void ajouterVoisine(Salle sa) { sallesVoisines.add(sa); } + public int getHauteurSousPlafond() { return hauteurSousPlafond; } + public void setHauteurSousPlafond(int hauteurSousPlafond) { this.hauteurSousPlafond = hauteurSousPlafond; } +} \ No newline at end of file diff --git a/AppOuvertures.java b/AppOuvertures.java new file mode 100644 index 0000000..3d77f63 --- /dev/null +++ b/AppOuvertures.java @@ -0,0 +1,46 @@ +package lepack; + +import java.util.ArrayList; + +public class AppOuvertures { + + private ArrayList listeBatiments; + + private ArrayList listePersonnel; + + public AppOuvertures() { + this.listeBatiments = new ArrayList<>(); + this.listePersonnel = new ArrayList<>(); + } + + public void ajouterBatiment(Batiment b) { + if (b != null) { + this.listeBatiments.add(b); + } + } + + public void ajouterPersonnel(Technicien p) { + if (p != null) { + this.listePersonnel.add(p); + } + } + + + public void afficherLePersonnel() { + System.out.println("--- LISTE DE TOUT LE PERSONNEL ---"); + for (Technicien p : listePersonnel) { + + // System.out.println(p.getFicheInfo()); + } + System.out.println("------------------------------------"); + } + + public void afficherLesBatiments() { + System.out.println("\n--- LISTE DES BATIMENTS ET LEURS SALLES ---"); + for (Batiment b : listeBatiments) { + b.afficherInfos(); + System.out.println("---"); + } + System.out.println("-------------------------------------------"); + } +} \ No newline at end of file diff --git a/Batiment.java b/Batiment.java new file mode 100644 index 0000000..ccc7926 --- /dev/null +++ b/Batiment.java @@ -0,0 +1,57 @@ +package lepack; + +import java.util.ArrayList; + +public class Batiment { + + + private String nom; + private ArrayList listeSalles; + + + public Batiment() { + listeSalles = new ArrayList(); + nom = "NC"; + } + + public Batiment(String n) { + listeSalles = new ArrayList(); + nom = n; + } + + + + public void afficherInfos() { + System.out.println("Batiment :" + nom); + + System.out.print("Liste des salles : "); + for (Salle s : listeSalles) { + s.afficherInfos(); + } + + } + + + public void ajouterSalle(Salle s) { + if (s==null) throw(new IllegalArgumentException("La salle ne doit pas être 'null'.")); + + listeSalles.add(s); + } + + public void supprimerSalle(Salle s) { + listeSalles.remove(s); + } + + public String getNom() { + return nom; + } + + public void setNom(String nom) { + this.nom = nom; + } + + public ArrayList getListeSalles() { + return this.listeSalles; + } + +} \ No newline at end of file diff --git a/Fenetre.java b/Fenetre.java new file mode 100644 index 0000000..93e567e --- /dev/null +++ b/Fenetre.java @@ -0,0 +1,19 @@ +package lepack; + +public class Fenetre extends Ouverture { + + private boolean doubleVitrage; + + public Fenetre(String numS, int larg, boolean hasDoubleVitrage) { + super(numS, larg); + this.doubleVitrage = hasDoubleVitrage; + } + public boolean aDoubleVitrage() { + return this.doubleVitrage; + } + @Override + public void afficherInfos() { + super.afficherInfos(); + System.out.println(" Type: Fenêtre" + (doubleVitrage ? " (Double vitrage)" : " (Simple vitrage)")); + } +} \ No newline at end of file diff --git a/GestionTravaux.java b/GestionTravaux.java new file mode 100644 index 0000000..ef160d4 --- /dev/null +++ b/GestionTravaux.java @@ -0,0 +1,31 @@ +package lepack; + +import java.util.ArrayList; + +public class GestionTravaux { + + private ArrayList listeBatiments; + private ArrayList listeOuvertures; + private ArrayList listeTechniciens; + + + public GestionTravaux() { + this.listeBatiments = new ArrayList<>(); + this.listeOuvertures = new ArrayList<>(); + this.listeTechniciens = new ArrayList<>(); + } + + + + + public ArrayList getOuverturesNecessitantPlusDeKTechniciens(int k) { + + ArrayList resultat = new ArrayList<>(); + for (Ouverture o : this.listeOuvertures) { + if (o.getNombreInstallateurs() > k) { + resultat.add(o); + } + } + return resultat; + } +} \ No newline at end of file diff --git a/Ouverture.java b/Ouverture.java new file mode 100644 index 0000000..6fc3584 --- /dev/null +++ b/Ouverture.java @@ -0,0 +1,88 @@ +package lepack; + +import java.util.ArrayList; + +public class Ouverture { + + //------------------------------------------------------------------------- + // PROPRIETES + private ArrayList listeTechniciens; + private Responsable superviseur; + private int largeur; + private String numeroSerie; + + public int getNombreInstallateurs() { + return this.listeTechniciens.size(); + } + + public Ouverture(String numS, int larg) { + this.numeroSerie = numS; + this.largeur = larg; + this.listeTechniciens = new ArrayList<>(); + this.superviseur = null; + } + + + public Ouverture() { + this.listeTechniciens = new ArrayList<>(); + largeur = 0; + numeroSerie="NC"; + } + + public Ouverture(String numS, int larg, Responsable s) { + largeur = larg; + numeroSerie = numS; + superviseur = s; + this.listeTechniciens = new ArrayList<>(); + } + + + + + + public void afficherInfos() { + System.out.println("Ouverture : " + numeroSerie); + System.out.println(" largeur : "+ largeur); + + if (superviseur!=null) { + // System.out.println(" superviseur : "+ superviseur.getNom()); //pour activer plus tardd + } else { + System.out.println(" superviseur : NC" ); + } + } + + + + // + + public Responsable getSuperviseur() { + return superviseur; + } + + public void setSuperviseur(Responsable superviseur) { + this.superviseur = superviseur; + } + + public int getLargeur() { + return largeur; + } + + public void setLargeur(int largeur) { + this.largeur = largeur; + } + + public String getNumeroSerie() { + return numeroSerie; + } + + public ArrayList getListeTechniciens() { + return this.listeTechniciens; + } + + public void setNumeroSerie(String numeroSerie) { + this.numeroSerie = numeroSerie; + } + + + +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..8c0f575 --- /dev/null +++ b/README.md @@ -0,0 +1,143 @@ +***Fichier généré par IA à partir des sources et de la liste des commits*** + +# TP Ouvertures - Cheminement pédagogique + +Ce projet illustre la construction progressive d'un système de gestion de bâtiments avec leurs salles et ouvertures. L'historique Git permet de retrouver chaque étape du développement. + +## Parcours des étapes + +### Étape 00 - Démarrage du projet +**Tag:** `etape00` + +- Classes importées initialement +- Pas de méthode main +- Définition du package non faite + +**Concepts abordés:** Structure initiale d'un projet Java + +--- + +### Étape 01 - Première classe exécutable +**Tag:** `etape01` + +- Ajout de la classe `ZeMain` avec une méthode `static void main` + +**Concepts abordés:** Point d'entrée d'une application Java + +--- + +### Étape 02 - Développement de la classe Salle +**Tag:** `etape02` + +- Implémentation complète de la classe `Salle` +- Ajout des propriétés (numéro, liste des ouvertures) +- Création des constructeurs (par défaut et paramétré) +- Méthodes d'accès (getters/setters) +- Méthode `afficherInfos()` + +**Concepts abordés:** +- Encapsulation +- Constructeurs +- Collections (ArrayList) +- Association entre classes + +--- + +### Étape 03 - Spécialisation avec la classe Amphi +**Tag:** `etape03` + +- Implémentation de la classe `Amphi` qui hérite de `Salle` +- Ajout de propriétés spécifiques (hauteurSousPlafond, sallesVoisines) +- Redéfinition de la méthode `afficherInfos()` + +**Concepts abordés:** +- Héritage +- Spécialisation +- Redéfinition de méthodes (override) +- Utilisation de `super` + +--- + +### Étape 04 - Tests et validation +**Tag:** `etape04` + +- Tests dans le main pour `Ouverture`, `Salle` et `Amphi` +- Création d'instances +- Tests des méthodes d'affichage + +**Concepts abordés:** +- Tests manuels +- Instanciation d'objets +- Manipulation des collections + +--- + +### Étape 05 - Gestion des bâtiments +**Tag:** `etape05` + +- Implémentation de la classe `Batiment` +- Gestion d'une liste de salles +- Ajout de tests dans le main + +**Concepts abordés:** +- Composition +- Navigation dans les associations +- Agrégation d'objets + +--- + +### Étape 06 - Gestion des exceptions +**Tag:** `etape06` (HEAD) + +- Ajout d'une levée d'exception dans `Batiment::ajouterSalle(Salle s)` +- Exemple de traitement d'exception dans le main avec try/catch +- Validation des paramètres (vérification de null) + +**Concepts abordés:** +- Gestion des exceptions en Java +- `throw` et `IllegalArgumentException` +- Blocs try/catch +- Validation des entrées +- Différence entre exception traitée et non traitée + +--- + +## Navigation dans l'historique + +Pour revenir à une étape spécifique : +```bash +git checkout etape00 # Remplacer par le numéro d'étape souhaité +``` + +Pour revenir à la version finale : +```bash +git checkout master +``` + +Pour voir les différences entre deux étapes : +```bash +git diff etape02 etape03 +``` + +## Structure du projet + +``` +src/travaux/ +├── ZeMain.java # Point d'entrée avec tests +├── Ouverture.java # Classe de base pour fenêtres/portes +├── Salle.java # Classe représentant une salle +├── Amphi.java # Spécialisation de Salle +├── Batiment.java # Agrégation de salles +├── Responsable.java # (non utilisé dans ce TP) +└── autres classes... +``` + +## Concepts Java couverts + +1. **POO de base:** Classes, objets, encapsulation +2. **Constructeurs:** Par défaut et paramétrés +3. **Collections:** ArrayList et manipulation +4. **Héritage:** Extension de classes, super +5. **Polymorphisme:** Redéfinition de méthodes +6. **Exceptions:** Levée et traitement +7. **Associations:** Composition et agrégation diff --git a/Responsable.java b/Responsable.java new file mode 100644 index 0000000..03747b7 --- /dev/null +++ b/Responsable.java @@ -0,0 +1,32 @@ +package lepack; + +import java.util.ArrayList; + +public class Responsable extends Technicien { + + + private ArrayList listeSupervisions; + + + public Responsable(String nom, int anneesExperience) { + + super(nom, anneesExperience); + + + this.listeSupervisions = new ArrayList<>(); + } + + + @Override + public void getFicheInfo() { + System.out.println("--- Fiche RESPONSABLE ---"); + System.out.println("Nom : " + getNom()); + System.out.println("A supervisé " + this.listeSupervisions.size() + " ouverture(s)."); + } + + public void ajouterSupervision(Ouverture o) { + if (o != null) { + this.listeSupervisions.add(o); + } + } +} \ No newline at end of file diff --git a/Salle.java b/Salle.java new file mode 100644 index 0000000..f3d5e04 --- /dev/null +++ b/Salle.java @@ -0,0 +1,60 @@ +package lepack; + +import java.util.ArrayList; + +public class Salle { + + + private String numero; // lecture/écriture + + private ArrayList listeOuvertures; + + + + public Salle() { + listeOuvertures = new ArrayList(); + numero = "NC"; + } + + public Salle(String num) { + listeOuvertures = new ArrayList(); + numero = num; + } + + + + public void afficherInfos() { + System.out.println("Salle numero : " + numero); + System.out.println("Ouvertures : "); + + for (Ouverture ouv : listeOuvertures) { + ouv.afficherInfos(); + } + } + + + + + + public void ajouterOuverture(Ouverture ouv) { + listeOuvertures.add(ouv); + } + + public void supprimerOuverture(Ouverture ouv) { + listeOuvertures.remove(ouv); + } + + public String getNumero() { + return numero; + } + + + public void setNumero(String numero) { + this.numero = numero; + } + + public ArrayList getListeOuvertures() { + return this.listeOuvertures; + } + +} \ No newline at end of file diff --git a/Technicien.java b/Technicien.java new file mode 100644 index 0000000..a0c155c --- /dev/null +++ b/Technicien.java @@ -0,0 +1,37 @@ +package lepack; +import java.util.*; + +public class Technicien { + + private ArrayList listeOuvertures; + private String nom; + private int anneesExperience; + + public Technicien(String nom, int anneesExperience) { + this.nom = nom; + this.anneesExperience = anneesExperience; + this.listeOuvertures = new ArrayList<>(); + } + + public void getFicheInfo() { + System.out.println("Technicien : " + this.nom + " (" + this.anneesExperience + " ans d'exp.)"); + } + + public void ajouterIntervention(Ouverture o) { + if (o != null) { + this.listeOuvertures.add(o); + } + } + + public int getSommeLargeurInterventions() { + int somme = 0; + for (Ouverture o : this.listeOuvertures) { + somme += o.getLargeur(); + } + return somme; + } + + public String getNom() { + return this.nom; + } +} \ No newline at end of file diff --git a/ZeMain.java b/ZeMain.java new file mode 100644 index 0000000..b017f18 --- /dev/null +++ b/ZeMain.java @@ -0,0 +1,49 @@ +package lepack; + +public class ZeMain { + + public static void main(String[] args) { + System.out.println("So far, so good... Yes I can spic ingliche.\n"); + + //---------------------------------------------- + + Ouverture ouv1 = new Ouverture("ouv 01", 90, null); + Ouverture ouv2 = new Ouverture("ouv 02", 70, null); + Ouverture ouv3 = new Ouverture("ouv 03", 50, null); + Ouverture ouv4 = new Ouverture("ouv 04", 180, null); + + Salle salle1 = new Salle("S001"); + salle1.ajouterOuverture(ouv1); + salle1.ajouterOuverture(ouv2); + + Amphi amphi1 = new Amphi("A123",500, true); + amphi1.ajouterOuverture(ouv4); + + Batiment bat1 = new Batiment("Usine à pizzas"); + bat1.ajouterSalle(salle1); + bat1.ajouterSalle(amphi1); + try { + bat1.ajouterSalle(salle1); + }catch(Exception e) { + System.out.println("Exception : " + e.getMessage()); + System.out.println("... on choisir de continuer quand même..."); + } + + + System.out.println("\n======= test salle 1 ======="); + salle1.afficherInfos(); + + System.out.println("\n======= test amphi 1 ======="); + amphi1.afficherInfos(); + + System.out.println("\n\n======= test batiment 1 ======="); + bat1.afficherInfos(); + + bat1.ajouterSalle(null); + + System.out.println("\n\nFin du prog sans plantage ! Yeees !"); + + + } + +}