-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFamille.java
More file actions
65 lines (53 loc) · 1.73 KB
/
Famille.java
File metadata and controls
65 lines (53 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package structural.composite;
import java.util.ArrayList;
import java.util.List;
public class Famille implements Personne {
private Personne conjoint1;
private Personne conjoint2;
private List<Personne> enfants;
public Famille(Personne conjoint1, Personne conjoint2) {
this.conjoint1 = conjoint1;
this.conjoint2 = conjoint2;
this.enfants = new ArrayList<>();
}
@Override
public void afficher(int niveau) {
String indentation = " ".repeat(niveau * 4);
System.out.println(indentation + "Famille:");
System.out.println(indentation + " Conjoints:");
conjoint1.afficher(niveau + 2);
conjoint2.afficher(niveau + 2);
System.out.println(indentation + " Enfants:");
for (Personne enfant : enfants) {
enfant.afficher(niveau + 2);
}
}
@Override
public void ajouterEnfant(Personne enfant) {
enfants.add(enfant);
}
@Override
public void ajouterConjoint(Personne conjoint) {
throw new UnsupportedOperationException("Une famille ne peut pas ajouter de conjoint.");
}
@Override
public List<Personne> getEnfants() {
return enfants;
}
@Override
public Personne getConjoint() {
throw new UnsupportedOperationException("Une famille ne peut pas avoir un conjoint unique.");
}
@Override
public String getNom() {
return conjoint1.getNom() + " & " + conjoint2.getNom();
}
@Override
public int getAge() {
throw new UnsupportedOperationException("Une famille n'a pas un âge unique.");
}
@Override
public String getSexe() {
throw new UnsupportedOperationException("Une famille n'a pas un sexe unique.");
}
}