salut tout le monde,
je vous passe le code des deux classes:
la classe Personne
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
public class Personne {
 
            public enum TSexe{
 
                masculin,
                feminin,
            };
                                            private String nom;
                                            private String prenom;
                                            private int age;
                                            private TSexe sexe;
     //constructeur par defaut
     public Personne()
     {
     this("","",0,TSexe.masculin);
     }
 
 
    public Personne(String nom, String prenom)
    {
    this(nom,prenom,0,TSexe.masculin);
    }
 
    public Personne(String nom, String prenom,int age)
    {
    this(nom,prenom,age,TSexe.masculin);
    }
 
    //constructeur complet
    public Personne(String nom, String prenom,int age,TSexe sexe)
    {
    this.setNom(nom);
    this.setPrenom(prenom);
    this.setAge(age);
    this.setSexe(sexe);
    }
 
    //constructeur personne
 
    public Personne(Personne personne)
    {
    this(personne.getNom(),personne.getPrenom(),personne.getAge(),personne.getSexe());    
    }
    //accesseurs
 
    public String getNom()
    {
            return this.nom;
    }
 
 
    public String getPrenom()
    {
            return this.prenom;
    }
 
    public int getAge()
    {
            return this.age;
    }
 
    public TSexe getSexe()
    {
            return this.sexe;
    }
 
    //muttateurs
 
    public void setNom(String nom)
    {
           this.nom=nom;
    }
 
    public void setPrenom(String prenom)
    {
           this.prenom=prenom;
    }
 
    public void setAge(int age)
    {
           if(age<0 || age>130)
                   this.age=0;
           else
                   this.age=age;
    }
 
 
    public void setSexe(TSexe sexe)
    {
           this.sexe=sexe;
    }
 
 
    public String toString()
    {
          return "MR "+this.getNom()+" "+this.getPrenom()+"est age de "+this.getAge()+" .et de sexe "+this.getSexe();
    }
 
 
}
et la classe TestPersonne:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class TestPersonne {
 
    public static void main(String[] args) {
 
        Personne p1 = new Personne();
        p1.setNom("kadachi");
        p1.setAge(27);
        p1.setSexe(TSexe.masculin);
        System.out.println(p1);
 
        Personne p2 = new Personne(p1);
        p2.setNom("hicham");
        p1.setAge(35);
        System.out.println(p2);
 
        Personne p3 = new Personne("falo","fati",29);
        p3.setSexe(TSexe.feminin);
        System.out.println(p3);
 
    }
je sais que je doit importer un truc pour que ca marche mais je l'ignore ?
merci d'avance