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
|
//import
public class Adherent {
private String nomAdhrent;
private String prenomAdhrent;
private String adresseAdherent;
//identificateur pour chaque adherent
Private static int numeroAdherent=0;
public Adherent(String nom,String prenom,String adresse){
nomAdherent=nom;
prenomAdherent=prenom;
adresseAdherent=adresse;
nbOuvragesEmpruntes=0;
numeroAdherent++;// je l'incremente ici
}
public String toString(Adherent a){
return "le nom de l'adherent de numero "+a.getNumeroAdherent(a)+" est "+a.getNomAdherent()+" "+a.getPrenomAdherent()+" actuellement il a emprunté "+a.getNbOuvragesEmpruntes()+" ouvrages";
}
public static void main(String[] args) {
// TODO Auto-generated method stub
LinkedList<Adherent> ad=new LinkedList<Adherent>();
Adherent lambda;
Scanner sc=new Scanner(System.in);
for (int i=0;i<2;i++){
System.out.println("saisir un nom");
String s1=sc.next();
System.out.println("saisir un prenom");
String s2=sc.next();
System.out.println("saisir une adresse");
String s3=sc.next();
lambda=new Adherent(s1,s2,s3);
ad.addLast(lambda);
}
for (int i=0;i<2;i++){
String affiche=ad.get(i).toString(ad.get(i));
System.out.println(affiche);
}
//affiche toujours le numeroAdhrent du dernier objet cree ????
} |