oehuizjio
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
import java.util.LinkedHashSet;
|
import java.util.*;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/** feuille du motif composite */
|
/** feuille du motif composite */
|
||||||
public class Chef extends Person {
|
public class Chef extends Person {
|
||||||
|
private List<Person> grp;
|
||||||
|
|
||||||
public boolean addSubalterne(Person p){
|
public boolean addSubalterne(Person p){
|
||||||
|
return grp.add(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -18,6 +19,7 @@ public class Chef extends Person {
|
|||||||
*/
|
*/
|
||||||
public Chef(int n){
|
public Chef(int n){
|
||||||
super(n);
|
super(n);
|
||||||
|
this.grp = new ArrayList<>();
|
||||||
// d'autres choses peut-être.
|
// d'autres choses peut-être.
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +31,11 @@ public class Chef extends Person {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public int bestPartyWithoutMe(){
|
public int bestPartyWithoutMe(){
|
||||||
// to do
|
int total = 0;
|
||||||
|
for (Person p : grp) {
|
||||||
|
total += p.bestParty(); // Chaque subalterne peut choisir de venir ou non
|
||||||
|
}
|
||||||
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,7 +46,12 @@ public class Chef extends Person {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public int bestParty(){
|
public int bestParty(){
|
||||||
// to do
|
int sansMoi = bestPartyWithoutMe();
|
||||||
|
int avecMoi = getFunFactor();
|
||||||
|
for (Person p : grp) {
|
||||||
|
avecMoi += p.bestPartyWithoutMe(); // Si je viens, mes subalternes ne peuvent pas venir
|
||||||
|
}
|
||||||
|
return Math.max(sansMoi, avecMoi);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,14 +15,14 @@ public class Travailleur extends Person {
|
|||||||
* @return fête sans le travailleur
|
* @return fête sans le travailleur
|
||||||
*/
|
*/
|
||||||
public int bestPartyWithoutMe(){
|
public int bestPartyWithoutMe(){
|
||||||
// return null;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return fête avec le travailleur
|
* @return fête avec le travailleur
|
||||||
*/
|
*/
|
||||||
public int bestParty(){
|
public int bestParty(){
|
||||||
// return null;
|
return getFunFactor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user