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
| class Personne3{
int age;
String nom,ntel;
Adresse adr;//champ qui se réfère à adresse
//le constructeur:
Personne3(int a,String n,String t)
{
age=a;
nom=n;
ntel=t;
}
Personne3(int a,String n,String t,int num,String r,String vil){
Personne3(a,n,t);
adr=new Adresse(num,r,vil);
}
class Adresse{
int numero;
String rue;
String ville;
Adresse(){
}
Adresse(int num,String r,String vil){
numero=num;
rue=r;
ville=vil;
}
}
//le modifieur:
void setAge(int ag)
{
if(age<0) System.out.println("age négatif, impossible");
else age=ag;
}
//l'accesseur:
int getAge()
{
return age;
}
String getNom()//rendre une valeur accessible en lecture
{
return nom;
}
public String toString()
{
return("l'age est de "+age);
}
boolean memeNom(Personne3 p)
{//fonction utilisée pour comparer les noms
if(nom.equals(p.nom)){
return true;
}
else{
return false;
}
}
} |
Partager