From 6c800f4e6fdf2e678ff974645c4a476d822d76c7 Mon Sep 17 00:00:00 2001 From: OMGiTzPomPom Date: Tue, 11 Oct 2022 10:04:27 +0200 Subject: [PATCH] fin TD4 --- Program.cs | 3 ++- TD4/Collaborateur.cs | 14 +++++++++++- TD4/Commercial.cs | 2 +- TD4/Employe.cs | 2 +- TD4/Manager.cs | 2 +- TD4/TD4.cs | 11 ++++----- TD4/TabCollaborateur.cs | 50 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 TD4/TabCollaborateur.cs diff --git a/Program.cs b/Program.cs index f41270e..d30867d 100644 --- a/Program.cs +++ b/Program.cs @@ -1,5 +1,6 @@ //using Programmation_objet_TLESIO21.TD1; //using Programmation_objet_TLESIO21.TD2; -using Programmation_objet_TLESIO21.TD3; +//using Programmation_objet_TLESIO21.TD3; +using Programmation_objet_TLESIO21.TD4; TD4.Launch(); diff --git a/TD4/Collaborateur.cs b/TD4/Collaborateur.cs index d4420bd..2c7f253 100644 --- a/TD4/Collaborateur.cs +++ b/TD4/Collaborateur.cs @@ -14,8 +14,20 @@ namespace Programmation_objet_TLESIO21.TD4 { this.DateNaissance = birthdate; } - public virtual double getSalaire() { + public override string ToString() { + return this.NOM + " - Age " + this.GetAge() + " - Salaire " + this.GetSalaire(); + } + + public virtual double GetSalaire() { return .0; } + + public String GetName() { + return this.NOM; + } + + public int GetAge() { + return 2022 - Int32.Parse(this.DateNaissance.Substring(4)); + } } } diff --git a/TD4/Commercial.cs b/TD4/Commercial.cs index 0859a65..bdd9e2e 100644 --- a/TD4/Commercial.cs +++ b/TD4/Commercial.cs @@ -15,7 +15,7 @@ namespace Programmation_objet_TLESIO21.TD4 { this.ChiffreAffaire = chiffreAffaire; } - public override double getSalaire() { + public override double GetSalaire() { return this.SalaireBase + this.ChiffreAffaire * T2; } diff --git a/TD4/Employe.cs b/TD4/Employe.cs index 684e47c..8f4a186 100644 --- a/TD4/Employe.cs +++ b/TD4/Employe.cs @@ -15,7 +15,7 @@ namespace Programmation_objet_TLESIO21.TD4 { this.NbHeures = nbHeures; } - public override double getSalaire() { + public override double GetSalaire() { double salaire = 0; if(this.NbHeures > 35) { diff --git a/TD4/Manager.cs b/TD4/Manager.cs index 3fcc776..83331ee 100644 --- a/TD4/Manager.cs +++ b/TD4/Manager.cs @@ -15,7 +15,7 @@ namespace Programmation_objet_TLESIO21.TD4 { this.Prime = prime; } - public override double getSalaire() { + public override double GetSalaire() { return this.SalaireBase + this.Prime; } diff --git a/TD4/TD4.cs b/TD4/TD4.cs index b92efbc..43527c7 100644 --- a/TD4/TD4.cs +++ b/TD4/TD4.cs @@ -32,15 +32,16 @@ namespace Programmation_objet_TLESIO21.TD4 { Console.WriteLine(tab.PlusHautSal("Commercial")); Console.WriteLine("TRI SUR AGE "); tab.Sort(); - foreach(Collaborateur c in tab) - Console.WriteLine(c); + foreach(Collaborateur c in tab.GetCollaborateurs()) + Console.WriteLine(c.ToString()); Console.WriteLine("TRI SUR SALAIRE "); - tab.Sort(new TriSalaire()); - foreach(Collaborateur c in tab) - Console.WriteLine(c) + tab.Sort("salaire"); + foreach(Collaborateur c in tab.GetCollaborateurs()) + Console.WriteLine(c); } public static void Launch() { + Exo1(); } diff --git a/TD4/TabCollaborateur.cs b/TD4/TabCollaborateur.cs new file mode 100644 index 0000000..7073493 --- /dev/null +++ b/TD4/TabCollaborateur.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace Programmation_objet_TLESIO21.TD4 { + public class TabCollaborateur { + private List collaborateurs; + + public TabCollaborateur() { + this.collaborateurs = new List(); + } + + public void Add(Collaborateur collaborateur) { + this.collaborateurs.Add(collaborateur); + } + + public List GetCollaborateurs() { + return this.collaborateurs; + } + + public String PlusHautSal(String t = "") { + String n = ""; + double sal = .0; + foreach(Collaborateur c in this.collaborateurs) { + + String tempT = c.GetType().ToString().Split(".")[2]; + if(t.Equals("") || t.Equals(tempT)) { + if(c.GetSalaire() > sal) { + n = c.GetName(); + } + } + } + return n; + } + + public void Sort(String type = "") { + if(type.Equals("")) { + this.collaborateurs.Sort((a,b) => a.GetAge().CompareTo(b.GetAge())); + } + + if(type.Equals("salaire")) { + this.collaborateurs.Sort((a, b) => a.GetSalaire().CompareTo(b.GetSalaire())); + } + + } + } +}