tp2correction
This commit is contained in:
35
Amphi.java
Normal file
35
Amphi.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package lepack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Amphi extends Salle {
|
||||
|
||||
private int hauteurSousPlafond;
|
||||
private boolean regie;
|
||||
private ArrayList<Salle> 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; }
|
||||
}
|
46
AppOuvertures.java
Normal file
46
AppOuvertures.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package lepack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class AppOuvertures {
|
||||
|
||||
private ArrayList<Batiment> listeBatiments;
|
||||
|
||||
private ArrayList<Technicien> 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("-------------------------------------------");
|
||||
}
|
||||
}
|
57
Batiment.java
Normal file
57
Batiment.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package lepack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Batiment {
|
||||
|
||||
|
||||
private String nom;
|
||||
private ArrayList<Salle> listeSalles;
|
||||
|
||||
|
||||
public Batiment() {
|
||||
listeSalles = new ArrayList<Salle>();
|
||||
nom = "NC";
|
||||
}
|
||||
|
||||
public Batiment(String n) {
|
||||
listeSalles = new ArrayList<Salle>();
|
||||
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<Salle> getListeSalles() {
|
||||
return this.listeSalles;
|
||||
}
|
||||
|
||||
}
|
19
Fenetre.java
Normal file
19
Fenetre.java
Normal file
@@ -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)"));
|
||||
}
|
||||
}
|
31
GestionTravaux.java
Normal file
31
GestionTravaux.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package lepack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GestionTravaux {
|
||||
|
||||
private ArrayList<Batiment> listeBatiments;
|
||||
private ArrayList<Ouverture> listeOuvertures;
|
||||
private ArrayList<Technicien> listeTechniciens;
|
||||
|
||||
|
||||
public GestionTravaux() {
|
||||
this.listeBatiments = new ArrayList<>();
|
||||
this.listeOuvertures = new ArrayList<>();
|
||||
this.listeTechniciens = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public ArrayList<Ouverture> getOuverturesNecessitantPlusDeKTechniciens(int k) {
|
||||
|
||||
ArrayList<Ouverture> resultat = new ArrayList<>();
|
||||
for (Ouverture o : this.listeOuvertures) {
|
||||
if (o.getNombreInstallateurs() > k) {
|
||||
resultat.add(o);
|
||||
}
|
||||
}
|
||||
return resultat;
|
||||
}
|
||||
}
|
88
Ouverture.java
Normal file
88
Ouverture.java
Normal file
@@ -0,0 +1,88 @@
|
||||
package lepack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Ouverture {
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// PROPRIETES
|
||||
private ArrayList<Technicien> 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<Technicien> getListeTechniciens() {
|
||||
return this.listeTechniciens;
|
||||
}
|
||||
|
||||
public void setNumeroSerie(String numeroSerie) {
|
||||
this.numeroSerie = numeroSerie;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
143
README.md
Normal file
143
README.md
Normal file
@@ -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
|
32
Responsable.java
Normal file
32
Responsable.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package lepack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Responsable extends Technicien {
|
||||
|
||||
|
||||
private ArrayList<Ouverture> 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);
|
||||
}
|
||||
}
|
||||
}
|
60
Salle.java
Normal file
60
Salle.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package lepack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Salle {
|
||||
|
||||
|
||||
private String numero; // lecture/écriture
|
||||
|
||||
private ArrayList<Ouverture> listeOuvertures;
|
||||
|
||||
|
||||
|
||||
public Salle() {
|
||||
listeOuvertures = new ArrayList<Ouverture>();
|
||||
numero = "NC";
|
||||
}
|
||||
|
||||
public Salle(String num) {
|
||||
listeOuvertures = new ArrayList<Ouverture>();
|
||||
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<Ouverture> getListeOuvertures() {
|
||||
return this.listeOuvertures;
|
||||
}
|
||||
|
||||
}
|
37
Technicien.java
Normal file
37
Technicien.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package lepack;
|
||||
import java.util.*;
|
||||
|
||||
public class Technicien {
|
||||
|
||||
private ArrayList<Ouverture> 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;
|
||||
}
|
||||
}
|
49
ZeMain.java
Normal file
49
ZeMain.java
Normal file
@@ -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 !");
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user