public class Ouvrage {
private String auteur;
private String titre;
private int nbExemplaires;
public Ouvrage(String auteur, String titre, int nbExemplaires) {
[Link] = auteur;
[Link] = titre;
[Link] = nbExemplaires;
}
public String getAuteur() {
return auteur;
}
public void setAuteur(String auteur) {
[Link] = auteur;
}
public String getTitre() {
return titre;
}
public void setTitre(String titre) {
[Link] = titre;
}
public int getNbExemplaires() {
return nbExemplaires;
}
public void setNbExemplaires(int nbExemplaires) {
[Link] = nbExemplaires;
}
public String toString() {
return "auteur=" + auteur + ", nbExemplaires=" + nbExemplaires
+ ", titre=" + titre;
}
}
public interface Empruntable {
void emprunter();
void rendre();
}
public class Livre extends Ouvrage implements Empruntable {
private int nbPages;
private int nbEmpruntes;
public Livre(String auteur, String titre, int nbExemplaires, int
nbPages) {
super(auteur, titre, nbExemplaires);
[Link] = nbPages;
[Link] = 0;
}
public void emprunter() {
if(estEmpruntable())
[Link]++;
}
public void rendre() {
[Link]--;
}
public boolean estEmpruntable() {
return getNbExemplaires() > nbEmpruntes;
}
public int nbDisponibles(){
return [Link]()-nbEmpruntes;
Examen POO A.U 2016-2017 1
}
public String toString() {
return [Link]()+"nbEmpruntes=" + nbEmpruntes + ",
nbPages=" + nbPages;
}
public class Adherent implements Empruntable{
private String nom;
private String prenom;
private int nbEmpruntsEnCours;
private int nbEmpruntsAutorises;
public Adherent(String nom, String prenom) {
[Link] = nom;
[Link] = prenom;
nbEmpruntsEnCours = 0;
nbEmpruntsAutorises = 3;
}
public String getNom() {
return nom;
}
public String getPrenom() {
return prenom;
}
public int getNbEmpruntsEnCours() {
return nbEmpruntsEnCours;
}
public int getNbEmpruntsAutorises() {
return nbEmpruntsAutorises;
}
public boolean aUnLivreEmprunte() {
return nbEmpruntsEnCours > 0;
}
public boolean peutEmprunter() {
return nbEmpruntsEnCours < nbEmpruntsAutorises;
}
public void emprunter() {
if(peutEmprunter())
nbEmpruntsEnCours++;
}
public void rendre() {
if(aUnLivreEmprunte())
nbEmpruntsEnCours--;
}
public String toString() {
return prenom + " " + nom ;
}
public class Emprunt {
private Livre livre;
private Adherent emprunteur;
public Emprunt(Livre unLivre, Adherent unemprunteur) {
if(unLivre != null &&[Link]()&&unemprunteur !=
null&&[Link]())
Examen POO A.U 2016-2017 2
{
livre = unLivre;
[Link]();
emprunteur = unemprunteur;
[Link]();
}
public Livre getLivre() {
return livre;
}
public Adherent getEmprunteur() {
return emprunteur;
}
public void terminer() {
[Link]();
[Link]();
}
public class Mediatheque {
private String nom;
private Ouvrage []tabOuvrage;
private Adherent []tabAdherent;
private Emprunt []tabEmprunt;
private int nbOuvrage;
private int nbAdherent;
private int nbEmprunt;
public Mediatheque(String nom) {
[Link] = nom;
[Link] = new Ouvrage[100];
[Link] = new Adherent[100];
[Link] = new Emprunt[100];
}
public boolean ajoutOuvrage(Ouvrage o)
{
if(nbOuvrage<[Link])
{tabOuvrage[nbOuvrage++]=o;
return true;
}
else return false;
}
public boolean ajoutAdherent(Adherent a)
{
if(nbAdherent<[Link])
{tabAdherent[nbAdherent++]=a;
return true;
}
else return false;
}
public boolean ajoutEmprunt(Emprunt e)
{
Examen POO A.U 2016-2017 3
if(nbEmprunt<[Link])
{tabEmprunt[nbEmprunt++]=e;
return true;
}
else return false;
}
public void afficheLivres()
{
for (int i=0; i<nbOuvrage;i++)
if(tabOuvrage[i]instanceof Livre)
[Link](tabOuvrage[i]);
}
public void listeAdherentAyantEmprunt()
{
for(int i=0; i<nbAdherent; i++)
if(tabAdherent[i].getNbEmpruntsEnCours()>0 )
[Link](tabAdherent[i]);
}
public void listeAdherentAyantEmprunt(String titre)
{
for(int i=0; i<nbAdherent; i++)
if(tabEmprunt[i].getLivre().getTitre().equals(titre) )
[Link](tabEmprunt[i].getEmprunteur());
}
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Mediatheque m = new Mediatheque("les roses");
Livre l=new Livre("Jacques Durand","Windows pour les debutants",
10, 500);
Disque d=new Disque("Fairouz","kifaq inta", 10, "Universal
Music");
[Link](l);
[Link](d);
Adherent a =new Adherent("Gates", "Bill");
[Link](a);
Emprunt e=new Emprunt(l,a);
[Link](e);
[Link]("nbdispo"+[Link]());
[Link]();
[Link]("Windows pour les debutants");
[Link]();
[Link]();
Examen POO A.U 2016-2017 4