Ouvrage.java
1.28 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package src;
public class Ouvrage implements Comparable<Ouvrage> {
// variables d'instance
protected String titre, auteur;
protected boolean emprunte;
protected int compteur; // nombre d'emprunts
// methodes et constructeurs
public Ouvrage(String tit, String aut) {
this.titre = tit;
this.auteur = aut;
}
public String toString() {
return "Titre; " + titre + " Auteur; " + auteur + " emprunter: " + emprunte;
}
public void emprunter() throws NonDisponibleException {
if (this.emprunte == true) {
throw new NonDisponibleException();
} else {
this.emprunte = true;
this.compteur++;
}
}
public void retourner() {
this.emprunte = false;
}
public int getCompteur() {
return this.compteur;
}
@Override
public int compareTo(Ouvrage ouvrage) {
if (this.compteur <= ouvrage.compteur) {
return -1;
} else {
return 1;
}
}
public void setTitre(String titre) {
this.titre = titre;
}
public void setAuteur(String auteur) {
this.auteur = auteur;
}
public void setEmprunte(boolean emprunte) {
this.emprunte = emprunte;
}
public void setCompteur(int compteur) {
this.compteur = compteur;
}
public String getTitre() {
return titre;
}
public String getAuteur() {
return auteur;
}
public boolean isEmprunte() {
return emprunte;
}
}