Advertisement
anthonimes

TPs3-4---POO

Nov 12th, 2020
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.03 KB | None | 0 0
  1. /* Main.java */
  2. package exo2;
  3.  
  4. import java.time.LocalDate;
  5.  
  6. public class Main {
  7.     public static void main(String[] args) {
  8.         Employe e = new Employe("Perez", 1500, LocalDate.of(1990,1,1));
  9.         Responsable r = new Responsable("PEREZ", 1500, LocalDate.now(), "CHEF", 100, e);
  10.  
  11.         Personnel p = new Personnel();
  12.  
  13.         System.out.println(p.ajouterEmploye(e));
  14.         System.out.println(p.ajouterEmploye(r));
  15.  
  16.         System.out.println(p);
  17.         System.out.println(p.montantSalairesBrutsMensuels());
  18.     }
  19. }
  20.  
  21. /* Personnel.java */
  22. package exo2;
  23.  
  24. import java.util.Arrays;
  25.  
  26. public class Personnel {
  27.     private Employe[] employes;
  28.     private int nb_employes;
  29.     private int capacite = 1000;
  30.  
  31.     public Personnel() {
  32.         this.employes = new Employe[this.capacite];
  33.         this.nb_employes = 0;
  34.     }
  35.  
  36.     public Employe rechercherEmploye(int matricule) {
  37.         for(int i = 0; i < this.nb_employes; i++) {
  38.             if(this.employes[i].getMatricule() == matricule)
  39.                 return this.employes[i];
  40.         }
  41.         return null;
  42.     }
  43.  
  44.     public boolean ajouterEmploye(Employe e) {
  45.         if(this.rechercherEmploye(e.getMatricule()) != null)
  46.             return false;
  47.         if(this.capacite == this.nb_employes+1) {
  48.             this.capacite *= 2;
  49.             Employe[] tmp = new Employe[this.capacite];
  50.             for(int i = 0; i < this.employes.length; i++)
  51.                 tmp[i] = this.employes[i];
  52.             this.employes = tmp;
  53.         }
  54.         this.employes[this.nb_employes++] = e;
  55.         return true;
  56.     }
  57.  
  58.     public double montantSalairesBrutsMensuels() {
  59.         double somme = 0;
  60.         for(int i = 0; i < this.nb_employes; i++) {
  61.             somme += this.employes[i].calculerSalaireBrutMensuel();
  62.         }
  63.         return somme;
  64.     }
  65.  
  66.     @Override
  67.     public String toString() {
  68.         String result = "";
  69.         for(int i = 0; i < this.nb_employes; i++)
  70.             result += this.employes[i].toString()+"\n";
  71.         return result;
  72.     }
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement