Skip to content

Commit

Permalink
Implementations of the Bibliotheque Class
Browse files Browse the repository at this point in the history
  • Loading branch information
EarvinKayonga committed Jun 10, 2015
1 parent 6cc298b commit 222682b
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 49 deletions.
2 changes: 1 addition & 1 deletion nbproject/private/private.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/Users/PapiMartial/Documents/NetBeansProjects/miniprojet/src/miniprojet/Miniprojet.java</file>
<file>file:/C:/Users/PapiMartial/Documents/NetBeansProjects/miniprojet/src/miniprojet/Mediatheque.java</file>
</group>
</open-files>
</project-private>
192 changes: 163 additions & 29 deletions src/miniprojet/Bibliotheque.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,77 +5,211 @@
*/
package miniprojet;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author PapiMartial
*/
public class Bibliotheque implements Serializable , Mediatheque{
public class Bibliotheque implements Serializable, Mediatheque {

@Override
public void afficherAdherents() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
private ArrayList<Adherent> adherents;
private ArrayList<Livre> livres;
private ArrayList<Emprunt> emprunts;

public Bibliotheque() {
this.adherents = new ArrayList<Adherent>();
this.livres = new ArrayList<Livre>();
this.emprunts = new ArrayList<Emprunt>();
}

public Bibliotheque(boolean val) throws FileNotFoundException, IOException, ClassNotFoundException {
//load from a file
ObjectInputStream in = new ObjectInputStream(
new FileInputStream("bibliotheque.txt"));
Object t = in.readObject();
if (t instanceof Bibliotheque) {
Bibliotheque b= (Bibliotheque) t;
new Bibliotheque(b.getAdherents(), b.getLivres(), b.getEmprunts());
} else {
System.out.println("Erreur");
}
in.close();


}

public Bibliotheque(ArrayList<Adherent> adherents, ArrayList<Livre> livres, ArrayList<Emprunt> emprunts) {
this.adherents = adherents;
this.livres = livres;
this.emprunts = emprunts;
}



@Override
public void afficheLivres() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public void recherche() {

}

public void updateLivre(Livre a) {

}

public void updateAdherent(Adherent a) {

}

@Override
public void afficheLecteursEnRetard() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

}

@Override
public void recherche() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public void afficheLivres() {

}

@Override
public void afficheDate() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public void afficherAdherents() {

}

@Override
public void ajoutAdherent() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public void afficheDate() {
Date date = new Date();
}

@Override
public void ajoutLivre() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public void ajoutAdherent(Adherent b) {
if (!this.adherents.contains(b)) {
this.getAdherents().add(b);
try {
this.save();
} catch (IOException ex) {
Logger.getLogger(Bibliotheque.class.getName()).log(Level.SEVERE, null, ex);
}
} else {

}
}

@Override
public void supprAdherent() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public void ajoutLivre(Livre b) {
if (!this.livres.contains(b)) {
this.getLivres().add(b);
try {
this.save();
} catch (IOException ex) {
Logger.getLogger(Bibliotheque.class.getName()).log(Level.SEVERE, null, ex);
}
} else {

}
}

@Override
public void supprLivre() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public void supprAdherent(Adherent a) {
if (this.getAdherents().contains(a)) {
this.getAdherents().remove(a);
try {
this.save();
} catch (IOException ex) {
Logger.getLogger(Bibliotheque.class.getName()).log(Level.SEVERE, null, ex);
}
} else {

}
}

@Override
public void emprunt() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public void supprLivre(Livre a) {
if (this.getLivres().contains(a)) {
this.getLivres().remove(a);
try {
this.save();
} catch (IOException ex) {
Logger.getLogger(Bibliotheque.class.getName()).log(Level.SEVERE, null, ex);
}
} else {

}
}

@Override
public void rendre() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public void emprunt(Livre a, Adherent b) {
if (!this.adherents.contains(b)) {
this.ajoutAdherent(b);
} else if (!a.isEmpruntable()) {
return;
}
this.getEmprunts().add(new Emprunt(b, a));
try {
this.save();
} catch (IOException ex) {
Logger.getLogger(Bibliotheque.class.getName()).log(Level.SEVERE, null, ex);
}
}

@Override
public void updateLivre() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public void rendre(Livre a, Adherent b) {
Emprunt t = null;
for (Emprunt cmp : this.getEmprunts()) {
if ((cmp.getLivre() == a) && (cmp.getEmprunteur() == b)) {
t = cmp;
}
}
if (t == null) {
return;
} else {
t.getLivre().setNbexemplairedispo(t.getLivre().getNbexemplairedispo() + 1);
this.getEmprunts().remove(t);
}
try {
this.save();
} catch (IOException ex) {
Logger.getLogger(Bibliotheque.class.getName()).log(Level.SEVERE, null, ex);
}

}

@Override
public void updateAdherent() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public void save() throws FileNotFoundException, IOException {
ObjectOutputStream output = new ObjectOutputStream(
new FileOutputStream("bibliotheque.txt"));
output.writeObject(this);

output.close();
}


/**
* @return the adherents
*/
public ArrayList<Adherent> getAdherents() {
return adherents;
}

/**
* @return the livres
*/
public ArrayList<Livre> getLivres() {
return livres;
}

/**
* @return the emprunts
*/
public ArrayList<Emprunt> getEmprunts() {
return emprunts;
}

}
27 changes: 16 additions & 11 deletions src/miniprojet/Emprunt.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,35 @@
* @author PapiMartial
*/
public class Emprunt {

private Adherent emprunteur;
private Livre livre;
private Date date;

public Emprunt(Adherent emprunteur, Livre livre) {
this.emprunteur = emprunteur;
this.livre = livre;
this.emprunteur.getLivres().add(livre);
if (livre.isEmpruntable()) {
this.emprunteur = emprunteur;
livre.setNbexemplairedispo(livre.getNbexemplairedispo() - 1);
this.livre = livre;
this.emprunteur.getLivres().add(livre);
this.date = new Date();
}else{

}
}
public Emprunt(Adherent emprunteur, Livre livre,Date date) {
this.date = date;

public Emprunt(Adherent emprunteur, Livre livre, Date date) {
this.date = date;
this.emprunteur = emprunteur;
this.livre = livre;
this.emprunteur.getLivres().add(livre);
}

@Override
public String toString() {
return " { Emprunt : "+ this.emprunteur.toString() + " emprunte "+ this.livre.toString() + " le " + this.getDate() +" }";
return " { Emprunt : " + this.emprunteur.toString() + " emprunte " + this.livre.toString() + " le " + this.getDate() + " }";
}



/**
* @return the emprunteur
*/
Expand Down Expand Up @@ -68,7 +75,5 @@ public void setLivre(Livre livre) {
public Date getDate() {
return date;
}




}
6 changes: 6 additions & 0 deletions src/miniprojet/Livre.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,16 @@ public void setNbexemplairedispo(int nbexemplairedispo) {
public String getCode() {
return this.theme.toString() + this.numero;
}

public boolean isEmpruntable(){
return this.nbexemplaires >= 0;
}

@Override
public String toString() {
return "{ Livre : " + "Titre : " + this.getTitre() + " Auteur : " + this.getAuteur() + " Code : " + this.getCode() + " }";
}



}
19 changes: 11 additions & 8 deletions src/miniprojet/Mediatheque.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

package miniprojet;

import java.util.ArrayList;


/**
*
* @author PapiMartial
Expand All @@ -11,14 +14,14 @@ public interface Mediatheque {
public void afficheLecteursEnRetard();
public void recherche();
public void afficheDate();
public void ajoutAdherent();
public void ajoutLivre();
public void supprAdherent();
public void supprLivre();
public void emprunt();
public void rendre();
public void updateLivre();
public void updateAdherent();
public void ajoutAdherent( Adherent b);
public void ajoutLivre( Livre b);
public void supprAdherent(Adherent b);
public void supprLivre( Livre b);
public void emprunt(Livre a, Adherent b);
public void rendre(Livre a, Adherent b);
public void updateLivre(Livre a);
public void updateAdherent(Adherent a);


}

0 comments on commit 222682b

Please sign in to comment.