Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eval #5

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
## Lest Start Java
# ipi-java-220-ex
![Build status](https://travis-ci.org/pjvilloud/ipi-java-220-ex.svg?branch=correction)

Expand Down
72 changes: 72 additions & 0 deletions src/main/java/com/ipiecoles/java/java220/Cadre.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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(){
}

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 Cadre(Double coefficient){
this.coefficient= coefficient;
}


public Double getCoefficient() {
return coefficient;
}

public void setCoefficient(Double coefficient) {
this.coefficient = coefficient;
}

@Override
public Double getPrimeAnnuelle() {
return Entreprise.primeAnnuelleBase()*coefficient;
//LocalDate.now().getYear()*0.5*coefficient
}

@Override
public Integer getNbConges(){
return Entreprise.NB_CONGES_BASE + coefficient.intValue();
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("Cadre{");
sb.append("nom='").append(super.getNom()).append('\'');
sb.append(", prenom='").append(super.getPrenom()).append('\'');
sb.append(", matricule='").append(super.getMatricule()).append('\'');
sb.append(", dateEmbauche=").append(super.getDateEmbauche()).append('\'');
sb.append(", salaire=").append(super.getSalaire()).append('\'');
sb.append(", tempsPartiel=").append(getTempsPartiel()).append('\'');
sb.append(", sexe=").append(getSexe()).append('\'');
sb.append(", coefficient=").append(coefficient).append('\'');
sb.append('}');
return sb.toString();
}

@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);
}

}
79 changes: 79 additions & 0 deletions src/main/java/com/ipiecoles/java/java220/Commercial.java
Original file line number Diff line number Diff line change
@@ -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 = 0.0;
private Integer performance;

public Commercial(){
}

public Double getCaAnnuel() {
return caAnnuel;
}

public void setCaAnnuel(Double caAnnuel) {
this.caAnnuel = caAnnuel;
}

public Double getPrimeAnnuelle(){
if(this.caAnnuel !=null){
return Math.max(Math.ceil(this.getCaAnnuel()*0.05),500);
}
return 500d;
}
public Commercial(String nom, String prenom, String matricule, LocalDate dateEmbauche, Double salaire, Double caAnnuel, Boolean tempsPartiel, String sexe) {
super(nom, prenom, matricule, dateEmbauche, salaire, tempsPartiel, sexe);
this.caAnnuel = caAnnuel;
}
public Commercial(String nom, String prenom, String matricule, LocalDate dateEmbauche, Double salaire,Double caAnnuel,Boolean tempsPartiel, String sexe, Integer performance) {
super(nom, prenom, matricule, dateEmbauche, salaire,tempsPartiel, sexe);
this.caAnnuel = caAnnuel;
this.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);
}
public Boolean performanceEgale(Integer perf){
return this.performance.equals(perf);
}
public Note equivalenceNote(){
switch (performance) {
case 0:
case 50:
return Note.INSUFFISANT;
case 100:
return Note.PASSABLE;
case 150:
return Note.BIEN;
case 200:
return Note.TRES_BIEN;
default:
return null;
}
}
public Integer getPerformance() {
return performance;
}
public void setPerformance(Integer performance) {
this.performance = performance;
}
@Override
public String toString() {
return "Commercial{" +
"caAnnuel=" + caAnnuel +
", performance=" + performance +
"} " + super.toString();
}
}
130 changes: 128 additions & 2 deletions src/main/java/com/ipiecoles/java/java220/Employe.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,133 @@
package com.ipiecoles.java.java220;

import org.joda.time.LocalDate;

import java.util.Objects;

/**
* Created by pjvilloud on 21/09/17.
* Started Project by Roja in 16/11/2021.
*/
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,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() - this.dateEmbauche.getYear();
}
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 LocalDate getDateEmbauche() {
return dateEmbauche;
}

public Boolean getTempsPartiel() {
return tempsPartiel;
}
public String getSexe() {
return sexe;
}

public void setSexe(String sexe) {
this.sexe = sexe;
}

public void setTempsPartiel(Boolean tempsPartiel) {
this.tempsPartiel = tempsPartiel;
}

public void setDateEmbauche(LocalDate dateEmbauche) throws Exception{
if (dateEmbauche != null && 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;
}

public void setSalaire(Double salaire) {
this.salaire = salaire;
}
public Integer getNbConges(){
return Entreprise.NB_CONGES_BASE;
}

@Override
public String toString() {
return "Employe{" +
"nom='" + nom + '\'' +
", prenom='" + prenom + '\'' +
", matricule='" + matricule + '\'' +
", dateEmbauche=" + dateEmbauche +
", salaire=" + salaire +
", tempsPartiel=" + tempsPartiel +
", sexe=" + sexe +
'}';
}
@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);
}
public void augmenterSalaire(Double pourcentage) {
this.salaire = this.getSalaire() * (1 + pourcentage);
}
public abstract Double getPrimeAnnuelle();


}

17 changes: 17 additions & 0 deletions src/main/java/com/ipiecoles/java/java220/Entreprise.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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 = 100.0;

public static Double primeAnnuelleBase(){
return LocalDate.now().getYear() * 0.5;
}

}
22 changes: 22 additions & 0 deletions src/main/java/com/ipiecoles/java/java220/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.ipiecoles.java.java220;

import org.joda.time.LocalDate;

public class Main {
public static void main (String[] args){
System.out.println("Hello to my Java world");
System.out.println(Entreprise.primeAnnuelleBase());
//employe = new Employe();
//Employe em1 = new Employe("justin", "carette", "J4587", new LocalDate(2019, 12, 15) ,10000.0);
//System.out.println(em1.getNom()+" have "+em1.getNombreAnneeAnciennete()+" ans experience in this company");
//System.out.println("employer info :"+em1.toString());
//em1.equals("justin");
//System.out.println(em1.getNom().equals("justin"));
//System.out.println(em1.hashCode());
//System.out.println(em1.augmenterSalaire(1.5));

//Cadre cadre1 = new Cadre( 1d , super("roaj", "gh"));
//System.out.println(cadre1.toString());
}

}
64 changes: 64 additions & 0 deletions src/main/java/com/ipiecoles/java/java220/Manager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.ipiecoles.java.java220;

import org.joda.time.LocalDate;

import java.text.Collator;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

public class Manager extends Employe{

private HashSet<Technicien> equipe = new HashSet<>();

public Manager(){}

public Manager(String nom, String prenom, String matricule, LocalDate dateEmbauche, Double salaire,Boolean tempsPartiel, String sexe, HashSet<Technicien> equipe){
super(nom, prenom, matricule, dateEmbauche, salaire, tempsPartiel,sexe);
this.equipe = equipe;
}
@Override
public Double getPrimeAnnuelle() {
return Entreprise.primeAnnuelleBase() + equipe.size() * Entreprise.PRIME_MANAGER_PAR_TECHNICIEN;
}

public HashSet<Technicien> getEquipe() {
return equipe;
}

public void setEquipe(HashSet<Technicien> equipe) {
this.equipe = equipe;
}

public void ajoutTechnicienEquipe(Technicien technicien){
equipe.add(technicien);
}

public void ajoutTechnicienEquipe(String nom, String prenom, String matricule, LocalDate dateEmbauche, Double salaire, Integer grade,Boolean tempsPartiel, String sexe) throws TechnicienException {
this.ajoutTechnicienEquipe(new Technicien(nom, prenom, matricule, dateEmbauche, salaire, grade, tempsPartiel,sexe));
}

public void setSalaire(Double salaire){
super.setSalaire(salaire * Entreprise.INDICE_MANAGER + (salaire * (double)equipe.size() / 10));
}

public void augmenterSalaire(Double pourcentage) {
super.augmenterSalaire(pourcentage);
augmenterSalaireEquipe(pourcentage);
}

private void augmenterSalaireEquipe(Double pourcentage) {
for (Technicien technicien : equipe) {
technicien.augmenterSalaire(pourcentage);
}
}

public List<Technicien> equipeParGrade(){
return equipe.stream().sorted(Technicien::compareTo).collect(Collectors.toList());
}

public double salaireEquipeGrade1(){
return equipe.stream().filter(t -> t.getGrade().equals(1)).mapToDouble(Technicien::getSalaire).sum();
}

}
Loading