-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathIndividu.java
More file actions
60 lines (48 loc) · 1.45 KB
/
Individu.java
File metadata and controls
60 lines (48 loc) · 1.45 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
package structural.composite;
import java.util.ArrayList;
import java.util.List;
public class Individu implements Personne {
private String nom;
private int age;
private String sexe;
public Individu(String nom, int age, String sexe) {
this.nom = nom;
this.age = age;
this.sexe = sexe;
}
@Override
public void afficher(int niveau) {
String indentation = " ".repeat(niveau * 4);
System.out.println(indentation + nom + ", " + age + " ans, " + sexe);
}
@Override
public void ajouterEnfant(Personne enfant) {
// Un individu simple ne peut pas avoir d'enfants directement.
throw new UnsupportedOperationException("Un individu simple ne peut pas avoir d'enfants.");
}
@Override
public void ajouterConjoint(Personne conjoint) {
// Un individu simple ne peut pas avoir de conjoint directement.
throw new UnsupportedOperationException("Un individu simple ne peut pas avoir de conjoint.");
}
@Override
public List<Personne> getEnfants() {
return new ArrayList<>(); // Un individu simple n'a pas d'enfants.
}
@Override
public Personne getConjoint() {
return null; // Un individu simple n'a pas de conjoint.
}
@Override
public String getNom() {
return nom;
}
@Override
public int getAge() {
return age;
}
@Override
public String getSexe() {
return sexe;
}
}