[Précédent]
[Index] | [Enoncé] | [Version imprimable]
[Prochain]

8.5
  EPFLiens - Corrigé
Niveau 2
 
 
Fichiers:
  Direction.java    

Le code complet est fourni ci-dessous.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import java.util.Calendar;
import java.util.ArrayList;

/**
 * Classe principale
   */
class Direction 
{
    public static void main(String[] args) {
        Ecole epfl = new Ecole();
        epfl.add(new EtudiantRegulier("Gaston Peutimide", 2020, "SSC", 6.0));
        epfl.add(new EtudiantRegulier("Yvan Rattrapeur", 2016, "SSC", 2.5));
        epfl.add(new EtudiantEchange("Bjorn Borgue", 2018, "Informatique", "KTH"));
        epfl.add(new Enseignant("Mathieu Matheu", 2015, "LMEP", 10000, "Physique"));
        epfl.add(new  Secretaire("Sophie Scribona", 2005, "LMT", 5000));
        epfl.afficherStatistiques();
        epfl.afficherEPFLiens();
    }

}

 /**
  * La direction
  */

class Ecole {
    private ArrayList<EPFLien> gens;

    public Ecole() {
        gens = new ArrayList<EPFLien>();
    }

    
    public void add(EPFLien personne)
        {
            if (personne != null)
            {
                gens.add(personne);
            }
        }
    
        /**
         * Cette méthode affiche l'ancienneté moyenne des personnes fréquentant  l'école
         * et le nombre d'étudiants parmi eux
         */
    public void afficherStatistiques() {

        System.out.println("Parmi les " + gens.size() + " EPFLiens, " +
                           EPFLien.getNbEtudiants() + " sont des etudiants.");
       
        System.out.println("Ils sont ici depuis en moyenne " + ancienneteMoyenne() + " ans");
    }

    

    // Cette méthode affiche les caractéristiques des personnes fréquentant  l'école
    public void afficherEPFLiens() {
        System.out.println("Liste des EPFLiens: ");
        for (EPFLien epflien : gens)
            epflien.afficher();
    }

    //un méthode utilitaire pour l'affichage des statistiques
    // (ne fait pas partie de l'API)
    private double ancienneteMoyenne()
        {
            if (gens.size() == 0) return 0.0;
            
            int anneeCourante = Calendar.getInstance().get(Calendar.YEAR);
            double moyenne = 0.0;
            
            for (EPFLien epflien : gens){
                moyenne += (anneeCourante - epflien.getAnnee());
            }
            return moyenne / gens.size();
        }
}


/**
  * Les personnes fréquentant l'EPFL
  */
class EPFLien {
    private String nom;
    private int annee;
    // un compteur statique pour compter le nombre d'étudiants
    private static int nombreEtudiants;
    

    public EPFLien(String nom, int annee) {
        this.nom = nom;
        this.annee = annee;
    }
    
   //Cette méthode affiche les caractéristiques générales d'un EPFLien
    public void afficher() {
        System.out.println("   Nom : " + getNom());
        System.out.println("   Annee : " + getAnnee());
    }

    public String getNom() {
        return nom;
    }

    public int getAnnee() {
        return annee;
    }

    public static int getNbEtudiants()
        {
            return nombreEtudiants;
        }
    
    protected void ajoutEtudiant()
        {
            ++nombreEtudiants;
        }
    
}

/**
  * Les étudiants
  */
class Etudiant extends EPFLien {
    private String section;

    public Etudiant(String nom, int annee, String section) {
        super(nom, annee);
        this.section = section;
        ajoutEtudiant();
    }

    public void afficher() {
        super.afficher();
        System.out.println("   Section : " + getSection());
    }

    public String getSection() {
        return section;
    }

}


/**
  * Les étudiants régulier
  */
class EtudiantRegulier extends Etudiant {
    private double moyenne;

    public EtudiantRegulier(String nom, int annee, String section, double moyenne) {
        super(nom, annee, section);
        this.moyenne = moyenne;
    }

    public void afficher() {
        System.out.println("Etudiant regulier:");
        super.afficher();
        System.out.println("   Moyenne : " + moyenne);
    }
}

/**
  * Les étudiants  d'échange
  */
class EtudiantEchange extends Etudiant {
    private String uniOrigine;

    public EtudiantEchange(String nom, int annee, String section, String uniOrigine) {
        super(nom, annee, section);
        this.uniOrigine = uniOrigine;
    }

    public void afficher() {
        System.out.println("Etudiant d'echange:");
        super.afficher();
        System.out.println("   Uni d'origine : " + getUniOrigine());
    }

    public String getUniOrigine() {
        return uniOrigine;
    }
}

/**
  * Le personnel de l'EPFL
  */
class Personnel extends EPFLien {
    private String labo;
    private int salaire;

    public Personnel(String nom, int annee, String labo, int salaire) {
        super(nom, annee);
        this.labo = labo;
        this.salaire = salaire;
    }

    public void afficher() {
        super.afficher();
        System.out.println("   Laboratoire : " + getLabo());
        System.out.println("   Salaire : " + getSalaire());
    }

    public String getLabo() {
        return labo;
    }

    public int getSalaire() {
        return salaire;
    }
}

class Enseignant extends Personnel {
    private String section;

    public Enseignant(String nom, int annee, String labo, int salaire, String section) {
        super(nom, annee, labo, salaire);
        this.section = section;
    }

    public void afficher() {
        System.out.println("Enseignant:");
        super.afficher();
        System.out.println("   Section d'enseignement : " + getSection());
    }

    public String getSection() {
        return section;
    }
}

class Secretaire extends Personnel {
    public Secretaire(String nom, int annee, String labo, int salaire) {
        super(nom, annee, labo, salaire);
    }

    public void afficher() {
        System.out.println("Secretaire:");
        super.afficher();
    }
}


 


[Précédent]
[Index] | [Enoncé] | [Version imprimable]
[Prochain]