From d7148186f55cb6c39aea38adbdf56e52523ce24f Mon Sep 17 00:00:00 2001 From: Felix-Vimalaratnam Date: Wed, 4 Dec 2024 17:26:25 +0100 Subject: [PATCH] manque l'ex 5 --- TP5/stub/exo3/Chef.class | Bin 0 -> 1022 bytes TP5/stub/exo3/Chef.java | 57 ++++++++++++++++++++++++++ TP5/stub/exo3/Exemple.class | Bin 0 -> 694 bytes TP5/stub/exo3/Exemple.java | 36 +++++++++++++++++ TP5/stub/exo3/Exemple2.class | Bin 0 -> 658 bytes TP5/stub/exo3/Exemple2.java | 33 +++++++++++++++ TP5/stub/exo3/Exemple3.class | Bin 0 -> 861 bytes TP5/stub/exo3/Exemple3.java | 43 ++++++++++++++++++++ TP5/stub/exo3/Person.class | Bin 0 -> 972 bytes TP5/stub/exo3/Person.java | 44 ++++++++++++++++++++ TP5/stub/exo3/Travailleur.class | Bin 0 -> 339 bytes TP5/stub/exo3/Travailleur.java | 27 +++++++++++++ TP5/stub/exo4/Chef.class | Bin 0 -> 1367 bytes TP5/stub/exo4/Chef.java | 69 ++++++++++++++++++++++++++++++++ TP5/stub/exo4/Exemple.class | Bin 0 -> 699 bytes TP5/stub/exo4/Exemple.java | 36 +++++++++++++++++ TP5/stub/exo4/Exemple2.class | Bin 0 -> 664 bytes TP5/stub/exo4/Exemple2.java | 33 +++++++++++++++ TP5/stub/exo4/Exemple3.class | Bin 0 -> 875 bytes TP5/stub/exo4/Exemple3.java | 43 ++++++++++++++++++++ TP5/stub/exo4/Person.class | Bin 0 -> 972 bytes TP5/stub/exo4/Person.java | 44 ++++++++++++++++++++ TP5/stub/exo4/Travailleur.class | Bin 0 -> 637 bytes TP5/stub/exo4/Travailleur.java | 37 +++++++++++++++++ TP5/stub/exo5/Chef.java | 48 ++++++++++++++++++++++ TP5/stub/exo5/Exemple.java | 36 +++++++++++++++++ TP5/stub/exo5/Exemple2.java | 33 +++++++++++++++ TP5/stub/exo5/Exemple3.java | 43 ++++++++++++++++++++ TP5/stub/exo5/Person.java | 44 ++++++++++++++++++++ TP5/stub/exo5/Travailleur.java | 31 ++++++++++++++ TP5/stubTPBamboche.tar.gz | Bin 0 -> 2042 bytes 31 files changed, 737 insertions(+) create mode 100644 TP5/stub/exo3/Chef.class create mode 100644 TP5/stub/exo3/Chef.java create mode 100644 TP5/stub/exo3/Exemple.class create mode 100644 TP5/stub/exo3/Exemple.java create mode 100644 TP5/stub/exo3/Exemple2.class create mode 100644 TP5/stub/exo3/Exemple2.java create mode 100644 TP5/stub/exo3/Exemple3.class create mode 100644 TP5/stub/exo3/Exemple3.java create mode 100644 TP5/stub/exo3/Person.class create mode 100644 TP5/stub/exo3/Person.java create mode 100644 TP5/stub/exo3/Travailleur.class create mode 100644 TP5/stub/exo3/Travailleur.java create mode 100644 TP5/stub/exo4/Chef.class create mode 100644 TP5/stub/exo4/Chef.java create mode 100644 TP5/stub/exo4/Exemple.class create mode 100644 TP5/stub/exo4/Exemple.java create mode 100644 TP5/stub/exo4/Exemple2.class create mode 100644 TP5/stub/exo4/Exemple2.java create mode 100644 TP5/stub/exo4/Exemple3.class create mode 100644 TP5/stub/exo4/Exemple3.java create mode 100644 TP5/stub/exo4/Person.class create mode 100644 TP5/stub/exo4/Person.java create mode 100644 TP5/stub/exo4/Travailleur.class create mode 100644 TP5/stub/exo4/Travailleur.java create mode 100644 TP5/stub/exo5/Chef.java create mode 100644 TP5/stub/exo5/Exemple.java create mode 100644 TP5/stub/exo5/Exemple2.java create mode 100644 TP5/stub/exo5/Exemple3.java create mode 100644 TP5/stub/exo5/Person.java create mode 100644 TP5/stub/exo5/Travailleur.java create mode 100644 TP5/stubTPBamboche.tar.gz diff --git a/TP5/stub/exo3/Chef.class b/TP5/stub/exo3/Chef.class new file mode 100644 index 0000000000000000000000000000000000000000..30c4d09ef9b5aab9f522f11909dfb1c741874ab3 GIT binary patch literal 1022 zcmX^0Z`VEs1_mbv2QCIC24;2!79Ivx1~x_pwt&>4;`}^D1~!|_yv!0iMg|rQPt7oP z1`b9B;jF~6ME%l|%p85kqN2n~pUmPCE(Uf6E|6YsMh0dL%`i>|UIspP27Vp}0R}-v z1{UXx)HFs0?&8v<#GI1UqP)~%Mg{>Ngh3!PthpJ48AR9_M0ps*7{nPF_)w)88JH7O zQWzOTH6Z$O67$ma{gbj%lS`~MqdFM542+;M3Z|z@xpBL5PVV z9Hg6x0i+ug#0(4)4Ezj|47Lmm49pCS{0xksAcq=}%D}|H!oa|w&1?fQU?+nFBZIHb zP6io9hM5fFIy)JZ7#R*QF!@RAZevhOuvz~9ne-a4S3stVF|aZ)FeouFF(@<0GpI1A zF{m3H%5r*nu5x4**eM#FGF3 literal 0 HcmV?d00001 diff --git a/TP5/stub/exo3/Chef.java b/TP5/stub/exo3/Chef.java new file mode 100644 index 0000000..61cb0a6 --- /dev/null +++ b/TP5/stub/exo3/Chef.java @@ -0,0 +1,57 @@ +import java.util.LinkedHashSet; +import java.util.Objects; +import java.util.ArrayList; +import java.util.List; + +/** feuille du motif composite */ +public class Chef extends Person { + private final List subalternes; + + /** constructeur + * + * @param n fun factor + */ + public Chef(int n) { + super(n); + this.subalternes = new ArrayList<>(); + } + + /** + * Ajoute un subalterne au chef + * @param p la personne à ajouter + */ + public void addSubalterne(Person p) { + if (p != null) subalternes.add(p); + } + + /** + * La meilleure fête avec moi, c'est la meilleure fête sans mes subalternes pour eux plus moi. + * + * @return retourne la valeur de la meilleure fête en invitant seulement les gens dont cette personne est le ou la supérieure hiérarchique, mais pas elle. + */ + @Override + public int bestPartyWithoutMe() { + int sum = 0; + for (Person subalterne : subalternes) { + sum += subalterne.bestParty(); // Additionne les meilleures fêtes de chaque subalterne + } + return sum; + } + + /** + * La meilleure fête est soit sans moi (c'est l'union des meilleures fêtes de mes subalternes), + * soit c'est la meilleure fête avec moi. + * + * @return la valeur de la meilleure fête en invitant seulement les gens dont cette personne est le ou la supérieure hiérarchique (peut-être avec elle). + */ + @Override + public int bestParty() { + int withMe = getFunFactor(); // Inclure le chef + for (Person subalterne : subalternes) { + withMe += subalterne.bestPartyWithoutMe(); // Ajouter les meilleures fêtes sans chaque subalterne + } + + int withoutMe = bestPartyWithoutMe(); // Meilleure fête sans inclure le chef + return Math.max(withMe, withoutMe); // Retourner la meilleure des deux options + } +} \ No newline at end of file diff --git a/TP5/stub/exo3/Exemple.class b/TP5/stub/exo3/Exemple.class new file mode 100644 index 0000000000000000000000000000000000000000..6091a29f6a353eb01cfa3ba532efb0c302dcc55a GIT binary patch literal 694 zcmX^0Z`VEs1_mbvT`mSD24;2!79Ivx1~x_pfvm)`ME#t^ymWp4q^#8B5=I6#o6Nk- z5<5l)W)00Sb_Nbc2JVoe#InT9oSf9sA}$7Y1}>0hZbk+c4Ns5?UPcBM=Zw@eE(RV3 zE)XHW!yw2Y#K^##n357)nv|GRl3J9P%E-X2;S-QrRGgn@tr^D2Ai^NZ&LGCaAkH9x z;*Q|T;*!){Mh52m(h^1nQ6I1iGxPNWiZb&`f=h~06LYOWwn*_XNHfSVGH@oP7MBDh z7L`HC zrm{1rF*2~bR;1<@DHQIj0{}C`K3k4scxAd#XL~+^gu3SP-IYLU}69PCI&`Oq%bfts53Ay$TBc8 zFfuSOuxf2*VBE;Sz`)3$!N9=41{P#w;AGHb(1I#G%fQUQ&cMJ>yPJVMl6^Y^rw@$b z3t|YcZD-*0+s(ie$+4Y*&x%EoMSB|qza)zenAF|Iz`uz>SdwKMgXA^_StwI!8-pxd zuN5muGb>0lnFMR49*O~41Nrv43P|y49N^q3|S1)4229b3^fdL42%rg3=9lR3_1Wa{DyA; literal 0 HcmV?d00001 diff --git a/TP5/stub/exo3/Exemple.java b/TP5/stub/exo3/Exemple.java new file mode 100644 index 0000000..9a23013 --- /dev/null +++ b/TP5/stub/exo3/Exemple.java @@ -0,0 +1,36 @@ +public class Exemple { + public static void main(String[] args) { + // bar 2 + // foo 5 + // titi 4 + // tata 4 + // toto 6 + // tete 6 + + Travailleur titi = new Travailleur(4); + Travailleur tata = new Travailleur(4); + Travailleur toto = new Travailleur(6); + + Chef foo = new Chef(5); + foo.addSubalterne(titi); + foo.addSubalterne(tata); + foo.addSubalterne(toto); + System.out.println(foo.bestParty()); + System.out.println(foo.bestPartyWithoutMe()); + + Travailleur tete = new Travailleur(6); + // System.out.println(tete.bestParty()); + // System.out.println(tete.bestPartyWithoutMe()); + + Chef bar = new Chef(2); + bar.addSubalterne(foo); + bar.addSubalterne(tete); + System.out.println(bar.bestParty()); + //System.out.println(bar.bestPartyWithoutMe()); + } + +} + + + + diff --git a/TP5/stub/exo3/Exemple2.class b/TP5/stub/exo3/Exemple2.class new file mode 100644 index 0000000000000000000000000000000000000000..f8c7472932fbe7c6cd226644284cb2dcdf122965 GIT binary patch literal 658 zcmX^0Z`VEs1_mbvEiMKo24;2!79Ivx1~x_pfvm)`ME#t^ymWp4q^#8B5=I6#o6Nk- z5<5l)W)00Sb_Nbc2JVoe#InT9oSf9sA}$7Y1}>0hZbk+c4Ns5?UPcBM=Zw@eE(RV3 zE)XHW!yw2Y#K^##n357)nv|GRl3J9P%E-X2;S-QrRGgn@tr^D2Ai^NZ&LGCaAkH9x z;*Q|T;*!){Mh52m(h^1nQ6I1iGxPNWiZb&`f=h~06LYOWwn*_XNHfSVGH@oP7MBDh z7L`C60tZ=eNl|8Ay0vB)BLi1(erZv1 zs#_*VF)z$OJ&@%LiVR8&Obj5v#J~s&cLqiV6$SQJS}7?>G27#JAJb~CU?vTbMJ^Z_y0w=;11?q=YL6yVySx| jL>Yn@#26wO#2JzqBp9+7q!>yWq!}0)G#D5dm>4txlren0 literal 0 HcmV?d00001 diff --git a/TP5/stub/exo3/Exemple2.java b/TP5/stub/exo3/Exemple2.java new file mode 100644 index 0000000..808a518 --- /dev/null +++ b/TP5/stub/exo3/Exemple2.java @@ -0,0 +1,33 @@ +public class Exemple2 { + public static void main(String[] args) { + // Exemple inspiré question Thibault B. + // 1 + // 10 + // 1 + // 1 + // 10 + // 3 + // 4 + + Travailleur a = new Travailleur(3); + Travailleur b = new Travailleur(4); + Chef c = new Chef(10); + c.addSubalterne(a); + c.addSubalterne(b); + Chef d = new Chef(1); + d.addSubalterne(c); + Chef e = new Chef(1); + e.addSubalterne(d); + Chef f = new Chef(10); + f.addSubalterne(e); + Chef g = new Chef(1); + g.addSubalterne(f); + + System.out.println(g.bestParty()); + } + +} + + + + diff --git a/TP5/stub/exo3/Exemple3.class b/TP5/stub/exo3/Exemple3.class new file mode 100644 index 0000000000000000000000000000000000000000..912c55c050dd00d513c0179cd59eccd40937ea6c GIT binary patch literal 861 zcmX^0Z`VEs1_mbvEiMKo24;2!79Ivx1~x_pfvm)`ME#t^ymWp4q^#8B5=I6#o6Nk- z5<5l)W)00Sb_Nbc2JVoe#InT9oSf9sA}$7Y1}>0hZbk+c4Ns5?UPcBM=Zw@eE(RV3 zE)XHW!yw2Y#K^##n357)nv|GRl3J9P%E-X2;S-QrRGgn@tr^D2Ai^NZ&LGCaAkH9x z;*Q|T;*!){Mh52m(h^1nQ6I1iGxPNWiZb&`f=h~06LYOWwn*_XNHfSVGH@oP7MBDh z7L`C60tZ=eNl|8Ay0vB)BLi1(erZv1 zs#_*VF)z$OJ&@%LiVR8&Obj5v#J~s&cLqiV6$SJX)j6B(Ep1Q-|?8Fw?VN3v~a;Pe48*tauq`tD}ni4@@4&cNrV ztG$hZUsq=v13yTNWjh0(6^kT`E;650l2wugDgf4G#U{xn$qE$#YhjmUmt+GAut$O{ zu;PGOWyJ|%34pA(;sRO00kVQyl3S8v8w0;2wU>>#atk~~mx0dD8pn1F@{+T;tUHJBp6mONHT0U|?d<1ORJ4;`}^D2F|q7Jh#N;lKdh@21ZXV z1`Y;Jb_OmU25tr(Mh1bb#Ii*FoW#6zegCAa)Z`LI1~!|_yv!0iMh0dL%`kQbK1K#5 zgd)$JoYeHh9LJ*c(%jU%64#34)Pj=C{5&BB1_l8h20;cPMh5ZR#Oze({JiAElJLxu z4Cnm3;*!L?l43>%Q4LQ`AB17SB}JKe>DF8fybK~B_lSa2V9INTF*5L^rB-2z;+&t7%E-X)lbM(5SDKrYS`?C)l#|NHz@p&^(!?8Fl9-(Bn^*u97D`GjE(u61 zDyamyE5EeFHs=qQxsmli7|mZerH z6cptb<+OH!>F8F)PN@=}YOa}tY-Q;XRdv>6#xG5mzhsq758j0|%4l`=B0LHxy{$iT$F z!N9=4$iM_j=nM=DEDVecVhrL8j0_SC3=Faij0}tn3=FJVTNoJEfE7wIFfg!z1^E~l z8Mqmwpi09Tm>HND7#L)YgE0s{jB2LmI6G6N%nB7-Ia0|OTWBZC%$4uc+pBmgIJ^D6)V literal 0 HcmV?d00001 diff --git a/TP5/stub/exo3/Person.java b/TP5/stub/exo3/Person.java new file mode 100644 index 0000000..b4f1951 --- /dev/null +++ b/TP5/stub/exo3/Person.java @@ -0,0 +1,44 @@ + +/** "Les personnes sont soit des chefs, soit des travailleurs" */ +public abstract class Person{ + /** + * valeur indiquant le niveau de coolitude de la personne + */ + private int funFactor; + + /** + * @return la valeur indiquant le niveau de coolitude de la personne. plus cete valeur est grande, plus la personne contribue à améliorer l'ambiance dans une fête. + * + */ + public int getFunFactor(){ + return this.funFactor; + } + + /** + * constructeur + * + * NB. Cette méthode ne peut pas être appelé directement pour instancier un objet car la classe est abstraite, mais sert dans les constructeurs de classes dérivées. + * + * @see Travailleur, Chef + */ + // + public Person(int n){ + if (n < 0) + throw new IllegalArgumentException("Le fun facteur est positif ou nul, vous avez proposé " + n); + this.funFactor = n; + } + + /** + * + * @return retourne la valeur de la meilleure fête en invitant seulement les gens dont cette personne est le ou la supérieure hiérarchique, mais pas elle. + */ + public abstract int bestPartyWithoutMe(); + + + /** + * + * @return la valeur de la meilleure fête en invitant seulement les gens dont cette personne est le ou la supérieure hiérarchique (peut-être avec elle). + */ + public abstract int bestParty(); +} + diff --git a/TP5/stub/exo3/Travailleur.class b/TP5/stub/exo3/Travailleur.class new file mode 100644 index 0000000000000000000000000000000000000000..a5320503c545146787b2ce0453d4f0a23f71a271 GIT binary patch literal 339 zcmX^0Z`VEs1_mbvVJ-$H24;2!79Ivx1~x_pwt&>4;`}^D1~!|_yv!0iMg|rQPt7nc z1`Y;Jb_OmU25tr(Mh5PXqQtVq%$%Im(jrC%p7hibx6(Yf#N?9vB1Q&g4NXr*1{UZ1 zlvG9rexJ;|RKL>Pq|~C2#H5^5Mh2mz)Z&tW#G;bQ@XV5o{L&KNR7M6)xF90~S8#r5 zQF5wVCP=jal1+M9iDiiliVPeKObj5v%)kh8Gy@|8F9QRE5(5)hoJ~u5I|JiJ1_lO3 z20jJ`29O6C7&sYN8Mqi28Tc7^pz5U<7#SED7#NtC*TB`Xfkgxv7#RfM>SUqnShcn> Ru%j!LWME_v1R2601OPCRHi7^E literal 0 HcmV?d00001 diff --git a/TP5/stub/exo3/Travailleur.java b/TP5/stub/exo3/Travailleur.java new file mode 100644 index 0000000..575376e --- /dev/null +++ b/TP5/stub/exo3/Travailleur.java @@ -0,0 +1,27 @@ +/** feuille du motif composite */ +public class Travailleur extends Person { + + /** constructeur + * + * @param n fun factor + */ + public Travailleur(int n) { + super(n); + } + + /** + * @return fête sans le travailleur + */ + @Override + public int bestPartyWithoutMe() { + return 0; // Contribution nulle si le travailleur n'est pas invité + } + + /** + * @return fête avec le travailleur + */ + @Override + public int bestParty() { + return getFunFactor(); // Contribution égale au fun factor si le travailleur est invité + } +} \ No newline at end of file diff --git a/TP5/stub/exo4/Chef.class b/TP5/stub/exo4/Chef.class new file mode 100644 index 0000000000000000000000000000000000000000..2d346cef9ce227ccb14db88c62ed80333c2c887b GIT binary patch literal 1367 zcmX^0Z`VEs1_mdF5H1EL24;2!79Ivx1~x_pwt&>4;`}^D1~!|_yv!0iMg|rQPt7n+ z1`Y;Jb_OmU25tr(Mg|t=jMOwn2HvF9;*x;GqLNDA)ZBbV24SD9#Ii*FoW#6zeb2m- z)b!LMYmiPp9tM7pHZi#R@XV5o{L&KNRFFn?20=y!aj@3XlFS@^pUk}M)D(}z;*8+b z5-tV-24RrnL>L*EH6Sh#<6#hIkYHrsE-p<<%qdAN%1bR~WRQf|j%kE77lRaoG&_R~ z4}&a&93z7u!YcoytkmR^VnznOqSV6D%%W7k{5-$XoE%05H4TVyV9!95S!-enft;tn z!=T8Z#K^#$n3BTCAc{?66iA&44}&U$8Y2ToW=U#MVo81xBZHU*)J(9eJ)z>(+zc8F zn(Pc(JPg_lI*bfL2nWNIFfy=bBo_OnR+NB)B?_cNkB32@!GMv0B@Zkt0y7)g3!vyW z;$bjmFkxiighvP13{NfwGX`^Z1`8erO9m@gFo88gBa@MVy(}@OG}S*1OXBLj18Vg(}utA?kirY9ol$P^TQW+WeeKPY>{YrC_Qj0U}9ikU}g{k zC0YhX25$xi1||j{1}0Em0<-xUco-NMSQr>Vd60pT!Iy!7!I^;>tWR1?dOHK77UNb1 zb`ZgC3|tIc4Ezj23{nij42%r^ z3;|FB)ft$;2J&ldVGz~c!612nfoU6q{2I6+Yz&MH3=A?1jG*{{YHDU+VqjrlV6fBL z!oYi+!HC%gqF9vo7Mo@BvI%qNjGuT01T3Z;{k2Bb5ZDX(_|k&O zJB}S>0*d357&sUh7_1oB8LSz27;G5S8EhH!80;7f85|hQ7#ta#7@QFf6oETXfPs-A I2po^W0IGH*cmMzZ literal 0 HcmV?d00001 diff --git a/TP5/stub/exo4/Chef.java b/TP5/stub/exo4/Chef.java new file mode 100644 index 0000000..a52a63b --- /dev/null +++ b/TP5/stub/exo4/Chef.java @@ -0,0 +1,69 @@ +import java.util.LinkedHashSet; +import java.util.Objects; + +/** feuille du motif composite */ +public class Chef extends Person { + private final LinkedHashSet subalternes; + + // Attributs pour mémoriser les résultats + private Integer bestPartyMemo = null; + private Integer bestPartyWithoutMeMemo = null; + + /** constructeur + * + * @param n fun factor + */ + public Chef(int n) { + super(n); + this.subalternes = new LinkedHashSet<>(); + } + + /** + * Ajoute un subalterne au chef + * + * @param p la personne à ajouter + * @return true si le subalterne a été ajouté, false sinon + */ + public boolean addSubalterne(Person p) { + return subalternes.add(Objects.requireNonNull(p)); + } + + /** + * La meilleure fête avec moi, c'est la meilleure fête sans mes subalternes pour eux plus moi. + * + * @return retourne la valeur de la meilleure fête en invitant seulement les gens dont cette personne est le ou la supérieure hiérarchique, mais pas elle. + */ + @Override + public int bestPartyWithoutMe() { + // Vérifie si la valeur est déjà calculée + if (this.bestPartyWithoutMeMemo == null) { + int sum = 0; + for (Person subalterne : subalternes) { + sum += subalterne.bestParty(); // Appelle uniquement bestParty(), qui est déjà mémorisé + } + this.bestPartyWithoutMeMemo = sum; // Mémorise le résultat + } + return this.bestPartyWithoutMeMemo; + } + + /** + * La meilleure fête est soit sans moi (c'est l'union des meilleures fêtes de mes subalternes), + * soit c'est la meilleure fête avec moi. + * + * @return la valeur de la meilleure fête en invitant seulement les gens dont cette personne est le ou la supérieure hiérarchique (peut-être avec elle). + */ + @Override + public int bestParty() { + // Vérifie si la valeur est déjà calculée + if (this.bestPartyMemo == null) { + int withMe = getFunFactor(); + for (Person subalterne : subalternes) { + withMe += subalterne.bestPartyWithoutMe(); // Inclut uniquement bestPartyWithoutMe(), déjà mémorisé + } + + int withoutMe = bestPartyWithoutMe(); // Utilise la version mémorisée + this.bestPartyMemo = Math.max(withMe, withoutMe); // Mémorise le meilleur résultat + } + return this.bestPartyMemo; + } +} diff --git a/TP5/stub/exo4/Exemple.class b/TP5/stub/exo4/Exemple.class new file mode 100644 index 0000000000000000000000000000000000000000..2bc41e65d18255ba665ed23b5dd364e47179a602 GIT binary patch literal 699 zcmX^0Z`VEs1_mbvT`mSD24;2!79Ivx1~x_pfvm)`ME#t^ymWp4q^#8B5=I6#o6Nk- z5<5l)W)00Sb_Nbc2JVoe#InT9oSf9sA}$7Y1}>0hZbk+c4Ns5?UPcBM=Zw@eE(RV3 zE)XHW!yw2Y#K^##n357)nv|GRl3J9P%E-X2;S-QrRGgn@tr^A1Ai^NZ&LGCaAkH9x z;*Q|T;*!){Mh52m(h^1nQ6I1iGxPNWiZb&`f=h~06LYOWwn*_XNHfSVGH@oP7MBDh z7L`HC zrm{1rF*2~bR;1<@DHQIj0{}C`K3k4scxAd#XL~+^gu3SP-IYLU}69PCI&`Oq%bfts53Ay$TBc8 zFfuSOuxf2*VBE;Sz`)3$!N9=41{P#w;AGHb(1I$x#K6qJ&cMLXw3~rFl6^Y^rw@$b z3t|YcZD-*0+s(ie$+4Y*&x%EoMSB|qf4C%z4usMLQJWZqC0VvHNN!`0g))`4G04KT zTd{)lvx4-qNwR@d@`p>ZNwUJUvO%;W+-b+a&%nUI#lXqH%^<|U!yv=J$Dqc*&!Ed7 zz+l24$Y9MN#Nfst%n-;R$`HdK$&kh%#gNA!%}~Z5!_dee$H2&-&A`CG#GnHJein#O literal 0 HcmV?d00001 diff --git a/TP5/stub/exo4/Exemple.java b/TP5/stub/exo4/Exemple.java new file mode 100644 index 0000000..9a23013 --- /dev/null +++ b/TP5/stub/exo4/Exemple.java @@ -0,0 +1,36 @@ +public class Exemple { + public static void main(String[] args) { + // bar 2 + // foo 5 + // titi 4 + // tata 4 + // toto 6 + // tete 6 + + Travailleur titi = new Travailleur(4); + Travailleur tata = new Travailleur(4); + Travailleur toto = new Travailleur(6); + + Chef foo = new Chef(5); + foo.addSubalterne(titi); + foo.addSubalterne(tata); + foo.addSubalterne(toto); + System.out.println(foo.bestParty()); + System.out.println(foo.bestPartyWithoutMe()); + + Travailleur tete = new Travailleur(6); + // System.out.println(tete.bestParty()); + // System.out.println(tete.bestPartyWithoutMe()); + + Chef bar = new Chef(2); + bar.addSubalterne(foo); + bar.addSubalterne(tete); + System.out.println(bar.bestParty()); + //System.out.println(bar.bestPartyWithoutMe()); + } + +} + + + + diff --git a/TP5/stub/exo4/Exemple2.class b/TP5/stub/exo4/Exemple2.class new file mode 100644 index 0000000000000000000000000000000000000000..ee5f2f8954f504147a1091e3e5c94789142ea4b7 GIT binary patch literal 664 zcmX^0Z`VEs1_mbvEiMKo24;2!79Ivx1~x_pfvm)`ME#t^ymWp4q^#8B5=I6#o6Nk- z5<5l)W)00Sb_Nbc2JVoe#InT9oSf9sA}$7Y1}>0hZbk+c4Ns5?UPcBM=Zw@eE(RV3 zE)XHW!yw2Y#K^##n357)nv|GRl3J9P%E-X2;S-QrRGgn@tr^A1Ai^NZ&LGCaAkH9x z;*Q|T;*!){Mh52m(h^1nQ6I1iGxPNWiZb&`f=h~06LYOWwn*_XNHfSVGH@oP7MBDh z7L`C60tZ=eNl|8Ay0vB)BLi1(erZv1 zs#_*VF)z$OJ&@%LiVR8&Obj5v#J~s&cLqiV6$SQJR;7?>G27#J98b~CU?vTbMJ^Z_y0w=;11?q=YL6yVyV8kHAV96lN;LISx;LRY) i5XK0hZbk+c4Ns5?UPcBM=Zw@eE(RV3 zE)XHW!yw2Y#K^##n357)nv|GRl3J9P%E-X2;S-QrRGgn@tr^A1Ai^NZ&LGCaAkH9x z;*Q|T;*!){Mh52m(h^1nQ6I1iGxPNWiZb&`f=h~06LYOWwn*_XNHfSVGH@oP7MBDh z7L`C60tZ=eNl|8Ay0vB)BLi1(erZv1 zs#_*VF)z$OJ&@%LiVR8&Obj5v#J~s&cLqiV6$SJX)j^BI^K1Q-|?`FAt0N3v~a;Pe48*tauq`tD}ni4@@4&cNrV ztG$hZKU`M_M1n+FwlnZqu}HG$q6n}`vP!bRM8F!Y*d*B`Sz$t8UF?$Vl57wW_DGO5 zRva)3tvEp}0gxlCxIor$fUMz`#URYk!XU!X&mhV$lR=DOA%i%>N(KprjSP|uyBVYy4l_tIoMVt-xW*vI@PI*{ i;RS;N!v_XMhTjZIjLZxwjC>5L42%pK3=9lR44MFOho^V| literal 0 HcmV?d00001 diff --git a/TP5/stub/exo4/Exemple3.java b/TP5/stub/exo4/Exemple3.java new file mode 100644 index 0000000..55651c9 --- /dev/null +++ b/TP5/stub/exo4/Exemple3.java @@ -0,0 +1,43 @@ +public class Exemple3 { + public static void main(String[] args) { + + Travailleur a = new Travailleur(3); + Travailleur b = new Travailleur(4); + Chef c = new Chef(10); + c.addSubalterne(a); + c.addSubalterne(b); + Chef d = new Chef(1); + d.addSubalterne(c); + Chef e = new Chef(1); + e.addSubalterne(d); + Chef f = new Chef(10); + f.addSubalterne(e); + Chef g = new Chef(1); + g.addSubalterne(f); + + Travailleur titi = new Travailleur(4); + Travailleur tata = new Travailleur(4); + Travailleur toto = new Travailleur(6); + Chef foo = new Chef(5); + foo.addSubalterne(titi); + foo.addSubalterne(tata); + foo.addSubalterne(toto); + Chef bar = new Chef(2); + bar.addSubalterne(foo); + Travailleur tete = new Travailleur(6); + bar.addSubalterne(tete); + + Chef x = new Chef(2); + x.addSubalterne(g); + x.addSubalterne(bar); + Chef y = new Chef(39); + y.addSubalterne(x); + + System.out.println(y.bestParty()); + } + +} + + + + diff --git a/TP5/stub/exo4/Person.class b/TP5/stub/exo4/Person.class new file mode 100644 index 0000000000000000000000000000000000000000..dc411fac2600035919a09b9c3141e43eee0e942e GIT binary patch literal 972 zcmX^0Z`VEs1_mbveNF}@24;2!79Ivx1~x_pwt&>4;`}^D2F|q7Jh#N;lKdh@21ZXV z1`Y;Jb_OmU25tr(Mh1bb#Ii*FoW#6zegCAa)Z`LI1~!|_yv!0iMh0dL%`kQbK1K#5 zgd)$JoYeHh9LJ*c(%jU%64#34)Pj=C{5&BB1_l8h20;cPMh5ZR#Oze({JiAElJLxu z4Cnm3;*!L?l43>%Q4LQ`AB17SB}JKe>DF8fybK~B_lSa2V9INTF*5L^rB-2z;+&t7%E-X)lbM(5SDKrYS`?C)l#|NHz@p&^(!?8Fl9-(Bn^*u97D`GjE(u61 zDyamyE5EeFHs=qQxsmli7|mZerH z6cptb<+OH!>F8F)PN@=}YOa}tY-Q;XRdv>6#xG5mzhsq758j0|%4l`=B0LHxy{$iT$F z!N9=4$iM_j=nM=DEDVecVhrL8j0_SC3=Faij0}tn3=FJVTNoJEfE7wIFfg!z1^E~l z8Mqmwpi09Tm>HND7#L)YgE0s{jB2LmI6G6N%nB7-Ia0|OTWBZC%$4uc+pBmgIJ^D6)V literal 0 HcmV?d00001 diff --git a/TP5/stub/exo4/Person.java b/TP5/stub/exo4/Person.java new file mode 100644 index 0000000..b4f1951 --- /dev/null +++ b/TP5/stub/exo4/Person.java @@ -0,0 +1,44 @@ + +/** "Les personnes sont soit des chefs, soit des travailleurs" */ +public abstract class Person{ + /** + * valeur indiquant le niveau de coolitude de la personne + */ + private int funFactor; + + /** + * @return la valeur indiquant le niveau de coolitude de la personne. plus cete valeur est grande, plus la personne contribue à améliorer l'ambiance dans une fête. + * + */ + public int getFunFactor(){ + return this.funFactor; + } + + /** + * constructeur + * + * NB. Cette méthode ne peut pas être appelé directement pour instancier un objet car la classe est abstraite, mais sert dans les constructeurs de classes dérivées. + * + * @see Travailleur, Chef + */ + // + public Person(int n){ + if (n < 0) + throw new IllegalArgumentException("Le fun facteur est positif ou nul, vous avez proposé " + n); + this.funFactor = n; + } + + /** + * + * @return retourne la valeur de la meilleure fête en invitant seulement les gens dont cette personne est le ou la supérieure hiérarchique, mais pas elle. + */ + public abstract int bestPartyWithoutMe(); + + + /** + * + * @return la valeur de la meilleure fête en invitant seulement les gens dont cette personne est le ou la supérieure hiérarchique (peut-être avec elle). + */ + public abstract int bestParty(); +} + diff --git a/TP5/stub/exo4/Travailleur.class b/TP5/stub/exo4/Travailleur.class new file mode 100644 index 0000000000000000000000000000000000000000..933f7256262cda8f499c1ec4c4d66a09cef073d6 GIT binary patch literal 637 zcmX^0Z`VEs1_mbv6)pxQ24;2!79Ivx1~x_pwt&>4;`}^D1~!|_yv!0iMg|rQPt7n+ z1`Y;Jb_OmU25tr(Mh5PXqQtVq%$%Im(jrC%-lWvxl7Pgbl1ksy+0CFYc-`lm56h-r9gVzCBfhByy{1cM|a14m|FNf<~yBLlOBrY9Ez2ZJ;ZgA7QD zCq1>qtu)UqF}Wnah>?NCIX@+pk%8YQGcVPzG&d==C?qi{CzX*w2-BsE47|Z5iOJc% zi3LzaoNz^q3|ztarA5i9ZkZt60!X2x2l5SrA_E5l69WSS69W?{Ai*qt1|9|m24)6E zPy{eAGRQJ8FqnWNB. Cette méthode ne peut pas être appelé directement pour instancier un objet car la classe est abstraite, mais sert dans les constructeurs de classes dérivées. + * + * @see Travailleur, Chef + */ + // + public Person(int n){ + if (n < 0) + throw new IllegalArgumentException("Le fun facteur est positif ou nul, vous avez proposé " + n); + this.funFactor = n; + } + + /** + * + * @return retourne la valeur de la meilleure fête en invitant seulement les gens dont cette personne est le ou la supérieure hiérarchique, mais pas elle. + */ + public abstract int bestPartyWithoutMe(); + + + /** + * + * @return la valeur de la meilleure fête en invitant seulement les gens dont cette personne est le ou la supérieure hiérarchique (peut-être avec elle). + */ + public abstract int bestParty(); +} + diff --git a/TP5/stub/exo5/Travailleur.java b/TP5/stub/exo5/Travailleur.java new file mode 100644 index 0000000..7df408b --- /dev/null +++ b/TP5/stub/exo5/Travailleur.java @@ -0,0 +1,31 @@ +/** feuille du motif composite */ +public class Travailleur extends Person { + + /** constructeur + * + * @param n fun factor + * + */ + public Travailleur(int n){ + super(n); + } + + /** + * + * @return fête sans le travailleur + */ + public int bestPartyWithoutMe(){ + // return null; + } + + /** + * @return fête avec le travailleur + */ + public int bestParty(){ + // return null; + } + + +} + + diff --git a/TP5/stubTPBamboche.tar.gz b/TP5/stubTPBamboche.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..4a5fecbd983e04a87ec6183ab3b2fc22c1b3052f GIT binary patch literal 2042 zcmb2|=3oE==C?7o^KQEdeBHb+Y2x$~>sD)PE-H}P!YQ@I;TBs#gPlli#6<1P;I5Dz z-mZBQ>R+z@E&XrfIX%zJ%E@o8Ez8W{o8a*<&SLlGImR-wE+;B(*;hvJF!bfFKEE)T z|IB$Fb?5Ay-Zcj^o*el4@WiHe^&@o&yG@c5GhI%coK$sYxlMxUU%svOfgDfkw{fmz zw_&;U|D5h$dzq&H#~)AZ{g=;V{eOSlhRFBKv6rj&w-l$iJb z;NIw%)t(Ja^UoJmG`>5;k%l6jF#$v_y z(~oqYG@4T5c1M7XLr>E3b$QswE6?=`YqeMcpLcKQO=(m=VJ+5apfKNhE+69(+2x5Z zjHLu#RZjmn<<}%v#@EYg!jvX2YrsY&Wn3gCb zD3*WXRDbKN1@2v|`)BklZaBdHg?GlRD&MO|jwFYEPh@;}aF#b$v_iz2&8p4$c6V~l z9bnRLso&}2bbe|XpU+C&G?kvKH5)?BuM1u`*0ZQtI&t>{`Q$RcX;Yd{h6u2gzj<5S zbnCyS&+k6BPp{1N#1nPu(_#-RZ}@M-l6_`woA0@4v0G1`@)0bWnU{LP)BNt+=YP=2L6tz6H?(Nlzrx)iq?%I8MR>aDhqN?iUZ$7r#eR;)M z`-Y+YMz`#L^~7(AMh(t?^8Jsw{@cDr@Ke3;1)YCy)~2mfsc@JQEa-aN#9vr?cIW52 z`%_ueRXPJ6%{=(2gzE|SnOT==y*|z_cKoT+U1IY=fhkb-xW|F(J;$_u?VP|+AbEJZ zib$H7YV&VTg{~j7oHhhc%(yX~__2&*YIf0pZ zCc9RDadxZWD*XB^-)Xw}bvu4#F~-doo=&-ZpjBGqQfITtCUNFm!*l0m)=bvDz_az` zsV7a{^ENVHRmo6uJ-X+?(JxQ+*T;QXu3!CRtD1m;REF3##RRL#7hUFlI-GU%&+P0+ zA2~klZ)q-hb}+FnLZ*GHQ=X_(6^A>6oaPOwS|K4bFF*Dtt(j~J5-C%wtVJfybj#Z0 z>vkyoXw2)`*=k;IG$oYZm#2S>QP17E_RaH^+LjZRZsD7BEzcot!oio{CN;&lJXF8Y z?*Bx6M!nzP_lqmng#A5yELEFxrIWba>|DEIrFy#l*l$!j@!wbBd)GW!#z}6+w+NPb96E0GWM0*o z=69+eVhsNO<#$@V(;_tg%pf)go(dU%9nS)5qlgb&l`4x_?g1sru7J4)!~R9wSDs&|-6WqjPP_QhS;=l{8v_J(~+z2>{^ z)VBJpRQ6EHQ^h6CN$>NkeAfn#aESiiK^O=c1Z@dx!aha~r=E2t@wb9=+(ljMcPj^?m9q{^u}R|KINXf98+- zatr<~mR#`9_@~2P^;htD|>$B z?*EUky|AC_^8e+6f15eq{JAgoclqQO_JRK|as>RJS+fA*B$vO>HzpqcpL?<1s`H<4 z{r^ms75`n}etCSYzAt+5|B^|+{xkgC&$-~==ZaO&O!uE(^v^h*4djkWn;ReNqrc4e zTlC)r$+?SPgDmd+|34by18~3;W`CLQ`S