ex2 tp3 urgent pour examen
Wed Nov 27 2024 01:02:17 GMT+0000 (Coordinated Universal Time)
Saved by @saharmess #mysql
class employe{ private String nom; private String pre; private int age; private float salaire; employe(){ this.nom="sahar"; this.pre="mess"; this.age=20; this.salaire=2500; } employe(String nom,String pre,int age,float salaire){ this.nom=nom; this.pre=pre; this.age=age; this.salaire=salaire; } employe(employe e){ this.nom=e.nom; this.pre=e.pre; this.age=e.age; this.salaire=e.salaire; } public String getNom(){ return this.nom; } public String getPre(){ return this.pre; } int getAge(){ return this.age; } float getSalaire(){ return this.salaire; } void setNom(String nom){ this.nom=nom; } void setPre(String pre){ this.pre=pre; } void setAge(int age){ this.age=age; } void setSalaire(float salaire){ this.salaire=salaire; } void aug(float sa){ this.salaire+=sa; } public String toString(){ String ch; ch="Nom:"+this.nom+" | Prenom:"+this.pre+"|age :"+this.age+" | le salaire :"+this.salaire; return ch; } void affiche(){ System.out.println(this.toString()); } } class tech extends employe{ private int grade; tech(){ this.grade=1; } tech(String nom,String pre,int age,float salaire,int grade){ super(nom,pre,age,salaire); setGrade(grade); } int getGrade(){ return this.grade; } void setGrade(int grade){ if(grade>=1 && grade<=3){ this.grade=grade; }else{ System.out.println("grade invalid il doit contenir 1,2 ou 3"); } } int prime(){ switch(grade){ case 1:return 100; case 2:return 200; case 3:return 300; default:return 0; } } public String toString(){ String ch; ch=super.toString()+"|le grade :"+this.grade+"| le prime :"+this.prime(); return ch; } void augme(){ super.aug(this.prime()); } } class equipe{ private tech[] tab; equipe(tech[] tab){ this.tab=tab; } public tech hisa(){ tech higs=tab[0]; for(tech t:tab) { if(t.getSalaire() > higs.getSalaire()){ higs=t; } } return higs; } public tech higa() { tech hig = tab[0]; for (tech t : tab) { if (t.getGrade() > hig.getGrade()) { hig = t; } } return hig; } } public class Main{ public static void main(String [] args){ employe e1=new employe("yasmin","tri",20,2500); tech t1=new tech("asma","ben",25,3000,2); e1.affiche(); t1.affiche(); e1.aug(200); e1.affiche(); t1.setGrade(2); t1.augme(); t1.affiche(); tech t22 = new tech("Lemoine", "Claire", 28, 1900, 2); tech t3 = new tech("Bernard", "Alice", 32, 2100, 1); tech t4 = new tech("Durand", "Eric", 27, 1950, 1); tech t5 = new tech("Morel", "Sophie", 26, 1850, 2); tech[] tab={t22,t3,t4,t5}; equipe eq=new equipe(tab); System.out.println("Highest Salary Technician: " + eq.hisa()); System.out.println("Highest Grade Technician: " + eq.higa()); } }
Comments