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
| public class Livre{
String titre;
String auteur;
int numeroArmoire;
int numeroRayon;
String codeClassification; //Je l'ai mit en String car je suppose qu'il y a des lettres
String nomEmprunteur;
boolean estEnPret; // je rajoute cet attribut car tu en aura besoin pour ta méthode estEnPret
public Livre(String titre, String auteur, int numeroArmoire, int numeroRayon, String codeClassification, String nomEmprunteur){
this.titre = titre;//le this désigne l'objet courant, c'est à dire l'objet qui sera instancié à partir de cette class, donc quand je fais this.titre je prend le champ titre de l'objet
this.auteur = auteur;
this.numeroArmoire = numeroArmoire;
this.numeroRayon = numeroRayon;
this.codeClassification = codeClassification;
this.nomEmprunteur = nomEmprunteur;
this.estEnPret = false;
}
//Les Methodes d'instance
public void empruntLivre(){
if(!estEnPret()){
this.estEnPret = true;
}else{
System.out.println("Le livre est déjà prêté");
}
}
public boolean estEnPret(){
return this.estEnPret;
}
public String nomLecteur(){
return this.nomEmprunteur;
}
public void rendLivre(){
this.estEnPret = false;
}
} |
Partager