diff --git a/pom.xml b/pom.xml index f68bdb83..e50b90fe 100644 --- a/pom.xml +++ b/pom.xml @@ -11,8 +11,8 @@ org.apache.maven.plugins maven-compiler-plugin - 16 - 16 + 15 + 15 diff --git a/src/main/java/com/ipiecoles/java/java220/Cadre.java b/src/main/java/com/ipiecoles/java/java220/Cadre.java new file mode 100644 index 00000000..0c789ac7 --- /dev/null +++ b/src/main/java/com/ipiecoles/java/java220/Cadre.java @@ -0,0 +1,63 @@ +package com.ipiecoles.java.java220; + +import org.joda.time.LocalDate; + +import java.util.Objects; + +public class Cadre extends Employe{ + + private Double coefficient = 1d; + + public Cadre(Double coefficient) { + this.coefficient = coefficient; + } + + public Cadre(String nom, String prenom, String matricule, LocalDate dateEmbauche, Double salaire, Double coefficient) { + super(nom, prenom, matricule, dateEmbauche, salaire); + this.coefficient = coefficient; + } + + public Cadre(String nom, String prenom, String matricule, LocalDate dateEmbauche, Double salaire, Boolean tempsPartiel, String sexe, Double coefficient) { + super(nom, prenom, matricule, dateEmbauche, salaire, tempsPartiel, sexe); + this.coefficient = coefficient; + } + + public Double getCoefficient() { + return coefficient; + } + + public void setCoefficient(Double coefficient) { + this.coefficient = coefficient; + } + + @Override + public Double getPrimeAnnuelle() { + return Entreprise.primeAnnuelleBase() * this.coefficient; + } + + @Override + public Integer getNbConges(){ + return Entreprise.NB_CONGES_BASE+ (int) Math.round(this.coefficient); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + Cadre cadre = (Cadre) o; + return Objects.equals(coefficient, cadre.coefficient); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), coefficient); + } + + @Override + public String toString() { + return "Cadre{" + + "coefficient=" + coefficient + + '}'; + } +} diff --git a/src/main/java/com/ipiecoles/java/java220/Commercial.java b/src/main/java/com/ipiecoles/java/java220/Commercial.java new file mode 100644 index 00000000..0e6c6aff --- /dev/null +++ b/src/main/java/com/ipiecoles/java/java220/Commercial.java @@ -0,0 +1,79 @@ +package com.ipiecoles.java.java220; + +import org.joda.time.LocalDate; + +import java.util.Objects; + +public class Commercial extends Employe{ + private Double caAnnuel; + private Integer performance; + + public Commercial(){ + + } + + public Commercial(String nom, String prenom, String matricule, + LocalDate dateEmbauche, Double salaire, Double caAnnuel) { + super(nom, prenom, matricule, dateEmbauche, salaire); + this.caAnnuel = caAnnuel; + } + + public Commercial(String nom, String prenom, String matricule, LocalDate dateEmbauche, Double salaire, Double caAnnuel, Integer performance) { + this(nom, prenom, matricule, dateEmbauche, salaire, caAnnuel); + this.performance = performance; + } + + @Override + public Double getPrimeAnnuelle() { + if (this.caAnnuel == null){ + return 500d; + } + return Math.max(Math.ceil(this.getCaAnnuel() * 0.05), 500d); + } + + public boolean performanceEgale(Integer performance){ + if (this.performance.equals(performance)){ + return true; + } + else + return false; + } + + public Double getCaAnnuel() { + return caAnnuel; + } + + public void setCaAnnuel(Double caAnnuel) { + this.caAnnuel = caAnnuel; + } + + public Integer getPerformance() { + return performance; + } + + public void setPerformance(Integer performance) { + this.performance = performance; + } + + @Override + public String toString() { + return "Commercial{" + + "caAnnuel=" + caAnnuel + + ", performance=" + performance + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + Commercial that = (Commercial) o; + return Objects.equals(caAnnuel, that.caAnnuel) && Objects.equals(performance, that.performance); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), caAnnuel, performance); + } +} diff --git a/src/main/java/com/ipiecoles/java/java220/Employe.java b/src/main/java/com/ipiecoles/java/java220/Employe.java index c217a6f4..2305a390 100644 --- a/src/main/java/com/ipiecoles/java/java220/Employe.java +++ b/src/main/java/com/ipiecoles/java/java220/Employe.java @@ -1,7 +1,139 @@ package com.ipiecoles.java.java220; +import org.joda.time.LocalDate; + +import java.util.Objects; + /** * Created by pjvilloud on 21/09/17. */ -public class Employe { +public abstract class Employe { + private String nom; + private String prenom; + private String matricule; + private LocalDate dateEmbauche; + private Double salaire; + private Boolean tempsPartiel; + private String sexe; + + public Employe() { + } + + public Employe(String nom, String prenom, String matricule, + LocalDate dateEmbauche, Double salaire) { + this.nom = nom; + this.prenom = prenom; + this.matricule = matricule; + this.dateEmbauche = dateEmbauche; + this.salaire = salaire; + } + + public Employe(String nom, String prenom, String matricule, LocalDate dateEmbauche, Double salaire, Boolean tempsPartiel, String sexe) { + this.nom = nom; + this.prenom = prenom; + this.matricule = matricule; + this.dateEmbauche = dateEmbauche; + this.salaire = salaire; + this.tempsPartiel = tempsPartiel; + this.sexe = sexe; + } + + public final Integer getNombreAnneeAnciennete (){ + return LocalDate.now().getYear()- dateEmbauche.getYear(); + } + + public Integer getNbConges(){ + return Entreprise.NB_CONGES_BASE; + } + + public void augmenterSalaire(Double pourcentage){ + this.salaire = this.getSalaire() * (1 + pourcentage); + } + + public abstract Double getPrimeAnnuelle(); + + public String getNom() { + return nom; + } + + public void setNom(String nom) { + this.nom = nom; + } + + public String getPrenom() { + return prenom; + } + + public void setPrenom(String prenom) { + this.prenom = prenom; + } + + public String getMatricule() { + return matricule; + } + + public void setMatricule(String matricule) { + this.matricule = matricule; + } + + public void setSalaire(Double salaire) { + this.salaire = salaire; + } + + public Boolean getTempsPartiel() { + return tempsPartiel; + } + + public void setTempsPartiel(Boolean tempsPartiel) { + this.tempsPartiel = tempsPartiel; + } + + public String getSexe() { + return sexe; + } + + public void setSexe(String sexe) { + this.sexe = sexe; + } + + public LocalDate getDateEmbauche() { + return dateEmbauche; + } + + public void setDateEmbauche(LocalDate dateEmbauche) throws Exception { + if (dateEmbauche.isAfter(LocalDate.now())){ + throw new Exception("La date d'embauche ne peut être postérieure à la date courante"); + } + this.dateEmbauche = dateEmbauche; + } + + public Double getSalaire() { + return salaire; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Employe employe = (Employe) o; + return Objects.equals(nom, employe.nom) && Objects.equals(prenom, employe.prenom) && Objects.equals(matricule, employe.matricule) && Objects.equals(dateEmbauche, employe.dateEmbauche) && Objects.equals(salaire, employe.salaire) && Objects.equals(tempsPartiel, employe.tempsPartiel) && Objects.equals(sexe, employe.sexe); + } + + @Override + public int hashCode() { + return Objects.hash(nom, prenom, matricule, dateEmbauche, salaire, tempsPartiel, sexe); + } + + @Override + public String toString() { + return "Employe{" + + "nom='" + nom + '\'' + + ", prenom='" + prenom + '\'' + + ", matricule='" + matricule + '\'' + + ", dateEmbauche=" + dateEmbauche + + ", salaire=" + salaire + + ", tempsPartiel=" + tempsPartiel + + ", sexe='" + sexe + '\'' + + '}'; + } } diff --git a/src/main/java/com/ipiecoles/java/java220/Entreprise.java b/src/main/java/com/ipiecoles/java/java220/Entreprise.java new file mode 100644 index 00000000..e74904f9 --- /dev/null +++ b/src/main/java/com/ipiecoles/java/java220/Entreprise.java @@ -0,0 +1,15 @@ +package com.ipiecoles.java.java220; +import org.joda.time.LocalDate; + +public class Entreprise { + public static final Double SALAIRE_BASE = 1480.27; + public static final Integer NB_CONGES_BASE = 25; + public static final Double INDICE_MANAGER = 1.3; + public static final Double PRIME_MANAGER_PAR_TECHNICIEN = 250.0; + public static final Double PRIME_ANCIENNETE = 100d; + + public static Double primeAnnuelleBase(){ + return LocalDate.now().getYear()/2d; + } + +} diff --git a/src/main/java/com/ipiecoles/java/java220/Manager.java b/src/main/java/com/ipiecoles/java/java220/Manager.java new file mode 100644 index 00000000..7c8489f2 --- /dev/null +++ b/src/main/java/com/ipiecoles/java/java220/Manager.java @@ -0,0 +1,65 @@ +package com.ipiecoles.java.java220; + +import org.joda.time.LocalDate; + +import java.util.HashSet; + +public class Manager extends Employe{ + + private HashSet equipe = new HashSet(); + + public Manager(){ + + } + + public Manager(String nom, String prenom, String matricule, LocalDate dateEmbauche, Double salaire, HashSet equipe) { + super(nom, prenom, matricule, dateEmbauche, salaire); + this.equipe = equipe; + } + + @Override + public Double getPrimeAnnuelle() { + return Entreprise.primeAnnuelleBase() + equipe.size() * Entreprise.PRIME_MANAGER_PAR_TECHNICIEN; + } + + public void ajoutTechnicienEquipe(Technicien technicien){ + equipe.add(technicien); + } + + public void ajoutTechnicienEquipe(String nom, String prenom, String matricule, LocalDate dateEmbauche, Double salaire, Integer grade) throws TechnicienException { + this.ajoutTechnicienEquipe(new Technicien(nom, prenom, matricule, dateEmbauche, salaire, grade)); + } + + @Override + public void setSalaire(Double salaire) { + super.setSalaire(salaire * Entreprise.INDICE_MANAGER + (salaire * equipe.size() / 10d)); + } + + public void augmenterSalaire(Double pourcentage) { + super.augmenterSalaire(pourcentage); + augmenterSalaireEquipe(pourcentage); + } + + private void augmenterSalaireEquipe(Double pourcentage) { + for (Technicien technicien : equipe) { + technicien.augmenterSalaire(pourcentage); + } + } + + + public HashSet getEquipe() { + return equipe; + } + + public void setEquipe(HashSet equipe) { + this.equipe = equipe; + } + + private class TechnicienException extends Exception { + } + + @Override + public String toString() { + return "Manager{} " + super.toString(); + } +} diff --git a/src/main/java/com/ipiecoles/java/java220/Technicien.java b/src/main/java/com/ipiecoles/java/java220/Technicien.java new file mode 100644 index 00000000..abaca1ca --- /dev/null +++ b/src/main/java/com/ipiecoles/java/java220/Technicien.java @@ -0,0 +1,68 @@ +package com.ipiecoles.java.java220; + +import org.joda.time.LocalDate; + +import java.util.Objects; + +public class Technicien extends Employe implements Comparable{ + private Integer grade; + + public Technicien(){ + + } + + public Technicien(String nom, String prenom, String matricule, LocalDate dateEmbauche, Double salaire, Integer grade) { + super(nom, prenom, matricule, dateEmbauche, salaire); + this.grade = grade; + } + + @Override + public void setSalaire(Double salaire) { + super.setSalaire(salaire * (1 + grade / 10d)); + } + + @Override + public Integer getNbConges() { + return super.getNbConges() + this.getNombreAnneeAnciennete(); + } + + @Override + public Double getPrimeAnnuelle() { + return Entreprise.primeAnnuelleBase()* (1 + grade / 10d) + + Entreprise.PRIME_ANCIENNETE * this.getNombreAnneeAnciennete(); + } + + public Integer getGrade() { + return grade; + } + + public void setGrade(Integer grade) { + + this.grade = grade; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + Technicien that = (Technicien) o; + return Objects.equals(grade, that.grade); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), grade); + } + + @Override + public int compareTo(Technicien o) { + if (this.grade o.getGrade()){ + return 1; + } + return 0; + } +} diff --git a/src/test/java/com/ipiecoles/java/java220/EntrepriseTest.java b/src/test/java/com/ipiecoles/java/java220/EntrepriseTest.java index 8c239552..f9e84e02 100644 --- a/src/test/java/com/ipiecoles/java/java220/EntrepriseTest.java +++ b/src/test/java/com/ipiecoles/java/java220/EntrepriseTest.java @@ -116,7 +116,7 @@ public void exo003ProgGenerique() throws Exception { class Derived extends Employe { //A decommenter quand le constructeur avec les 5 arguments est codé public Derived(String nom, String prenom, String matricule, LocalDate dateEmbauche, Double salaire) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { - //super(nom, prenom, matricule, dateEmbauche, salaire); + super(nom, prenom, matricule, dateEmbauche, salaire); } public Derived() {