Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Main.java */
- package exo2;
- import java.time.LocalDate;
- public class Main {
- public static void main(String[] args) {
- Employe e = new Employe("Perez", 1500, LocalDate.of(1990,1,1));
- Responsable r = new Responsable("PEREZ", 1500, LocalDate.now(), "CHEF", 100, e);
- Personnel p = new Personnel();
- System.out.println(p.ajouterEmploye(e));
- System.out.println(p.ajouterEmploye(r));
- System.out.println(p);
- System.out.println(p.montantSalairesBrutsMensuels());
- }
- }
- /* Personnel.java */
- package exo2;
- import java.util.Arrays;
- public class Personnel {
- private Employe[] employes;
- private int nb_employes;
- private int capacite = 1000;
- public Personnel() {
- this.employes = new Employe[this.capacite];
- this.nb_employes = 0;
- }
- public Employe rechercherEmploye(int matricule) {
- for(int i = 0; i < this.nb_employes; i++) {
- if(this.employes[i].getMatricule() == matricule)
- return this.employes[i];
- }
- return null;
- }
- public boolean ajouterEmploye(Employe e) {
- if(this.rechercherEmploye(e.getMatricule()) != null)
- return false;
- if(this.capacite == this.nb_employes+1) {
- this.capacite *= 2;
- Employe[] tmp = new Employe[this.capacite];
- for(int i = 0; i < this.employes.length; i++)
- tmp[i] = this.employes[i];
- this.employes = tmp;
- }
- this.employes[this.nb_employes++] = e;
- return true;
- }
- public double montantSalairesBrutsMensuels() {
- double somme = 0;
- for(int i = 0; i < this.nb_employes; i++) {
- somme += this.employes[i].calculerSalaireBrutMensuel();
- }
- return somme;
- }
- @Override
- public String toString() {
- String result = "";
- for(int i = 0; i < this.nb_employes; i++)
- result += this.employes[i].toString()+"\n";
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement