1 pièce(s) jointe(s)
Gestion d'une petite bibliothèque
salut,
happy new year :D
l’énoncé de l'exercice est sur la pièce joint
j'ai trouver des problèmes dans l’implémentation des méthodes de la 3 ème question et la méthode de la classe Livre ( empruntable():boolean )
voici les codes:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| public class Test{
public static void main(String [] args){
Bibliotheque bibli = new Bibliotheque();
Adherent ad = new Adherent("fussa","fyby");
Adherent ad2 = new Adherent("slim","shady");
bibli.ajouterAdherent(ad);
bibli.ajouterAdherent(ad2);
int n=4;
Document[] docs = new Document[n];
docs[0]=new Livre("misérables","hugo victor");
docs[1]=new Journal("dr dobbs",11,10,2003);
docs[2]=new BD("thorgal","van hamme","rosinky");
docs[3]=new Livre("systemes","ferber");
for(int i=0;i<n;i++){
System.out.println("document "+docs[i]);
bibli.ajouterDocument(docs[i]);
}
bibli.listerDocuments();
bibli.recupererDocuments();
}
} |
Code:
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
| import java.util.Vector;
import java.io.*;
public class Bibliotheque{
private Vector adherents;
private Vector documents;
public Bibliotheque(){
adherents= new Vector();
documents= new Vector();
}
public void ajouterAdherent(Adherent ad){
adherents.addElement(ad);
}
public void ajouterDocument(Document doc){
documents.addElement(doc);
}
public void listerDocuments(){
ObjectOutputStream oos;
int i,s = documents.size();
try{
oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(new File("file.txt"))));
for (i=0; i<s;i++){
oos.writeObject(documents.get(i));
}
oos.close();
} catch (IOException e){
e.printStackTrace();
}
}
public void recupererDocuments(){
ObjectInputStream ois;
try{
ois = new ObjectInputStream(new BufferedInputStream(new FileInputStream(new File("file.txt"))));
System.out.println("affichage des documents :");
System.out.println("*************************");
int s= documents.size();
try{
for(int i=0;i<s;i++){
}
System.out.println(((Document)ois.readObject()).toString());
}catch(ClassNotFoundException e){
e.printStackTrace();
}
ois.close();
}catch (IOException e) {
e.printStackTrace();
}
}
} |
Code:
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
| import java.io.Serializable;
public class Adherent implements Serializable {
private String prenom;
private String nom;
public Adherent(){
this.prenom="Inconnu";
this.nom="Inconnu";
}
public Adherent(String prn,String nm){
this.prenom=prn;
this.nom=nm;
}
public void setNom(String nm){
this.nom=nm;
}
public void setPrenom(String prn){
this.prenom=prn;
}
public String getNom(){
return this.nom;
}
public String getPrenom(){
return this.prenom;
}
public String toString(){
return "nom : "+this.getNom()+" , prenom : "+this.getPrenom();
}
public void emprunter(Livre l){
l.empruntable();
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| import java.io.Serializable;
public class Document implements Serializable {
private String titre;
public Document(){
this.titre="Inconnu";
}
public Document(String ttr){
this.titre=ttr;
}
public void setTitre(String ttr){
this.titre=ttr;
}
public String getTitre(){
return this.titre;
}
public String toString(){
return "titre du document : "+this.getTitre();
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
public class Volume extends Document{
private String auteur;
public Volume(){
super();
this.auteur="Inconnu";
}
public Volume(String ttr,String aut){
super(ttr);
this.auteur=aut;
}
public void setAuteur(String aut){
this.auteur=aut;
}
public String getAuteur(){
return this.auteur;
}
public String toString(){
return "auteur : "+this.getAuteur()+" , "+super.toString();
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
public class Journal extends Document {
private Date dt;
public Journal(){
super();
this.dt= new Date();
}
public Journal(String ttr,int dy,int mth,int yr){
super(ttr);
this.dt= new Date(dy,mth,yr);
}
public String toString(){
return "date : "+this.dt.toString()+" , "+super.toString();
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
public class BD extends Volume {
private String dessinateur;
public BD(){
super();
this.dessinateur="Inconnu";
}
public BD(String ttr,String aut,String nomD){
super(ttr,aut);
this.dessinateur=nomD;
}
public String getNomDessinateur(){
return this.dessinateur;
}
public void setNomDessinateur(String nomD){
this.dessinateur=nomD;
}
public String toString(){
return "dessinateur : "+this.getNomDessinateur()+" , "+super.toString();
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
public class Livre extends Volume {
public Livre(){
super();
}
public Livre(String ttr,String aut){
super(ttr,aut);
}
public String toString(){
return "livre => "+super.toString();
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
public class Dictionnaire extends Volume {
public Dictionnaire(){
super();
}
public Dictionnaire(String ttr,String aut){
super(ttr,aut);
}
public String toString(){
return "dictionnaire => "+super.toString();
}
} |
Code:
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
| import java.io.Serializable;
public class Date implements Serializable {
private int day;
private int month;
private int year;
public Date(){
this.day=0;
this.month=0;
this.year=0;
}
public Date(int dy,int mth,int yr){
this.day=dy;
this.month=mth;
this.year=yr;
}
public void setDay(int dy){
this.day=dy;
}
public void setMonth(int mth){
this.month=mth;
}
public void setYear(int yr){
this.year=yr;
}
public int getDay(){
return this.day;
}
public int getMonth(){
return this.month;
}
public int getYear(){
return this.year;
}
public String toString(){
return this.getDay()+"/"+this.getMonth()+"/"+this.getYear();
}
} |