Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
2c79daa4b9 |
@@ -23,7 +23,12 @@ public class GestionBibliotheque {
|
|||||||
int choix=0;
|
int choix=0;
|
||||||
Bibliotheque laBibli = new Bibliotheque();
|
Bibliotheque laBibli = new Bibliotheque();
|
||||||
ArrayList<Livre> mesLivres = new ArrayList<>();
|
ArrayList<Livre> mesLivres = new ArrayList<>();
|
||||||
Livre l1 = new Livre("Le secret des secrets","Dan Brown","9782709668385",true);
|
Utilisateur unUtilisateur = new Utilisateur("Emile", mesLivres);
|
||||||
|
Livre ll = new Livre(1,"Le secret des secrets","Dan Brown","9782709668385",true);
|
||||||
|
Livre l2 = new Livre(2,"Le secret des secrets","Dan Brown","9772709668385",true);
|
||||||
|
Livre l3 = new Livre(3,"Le secret des secrets","Dan Brown","9712709668385",true);
|
||||||
|
Livre l4 = new Livre(4,"Le secret des secrets","Dan Brown","9792709668385",true);
|
||||||
|
Livre l5 = new Livre(5,"Le secret des secrets","Dan Brown","9282709668385",false);
|
||||||
//Utilisateur u1 = new Utilisateur("Alice", mesLivres.add(l1));
|
//Utilisateur u1 = new Utilisateur("Alice", mesLivres.add(l1));
|
||||||
|
|
||||||
System.out.println("Bienvenue dans la bibliothèque !");
|
System.out.println("Bienvenue dans la bibliothèque !");
|
||||||
@@ -36,15 +41,36 @@ public class GestionBibliotheque {
|
|||||||
choix = sc.nextInt();
|
choix = sc.nextInt();
|
||||||
switch (choix) {
|
switch (choix) {
|
||||||
case 1 :
|
case 1 :
|
||||||
System.out.println("---Livre : " + l1.getTitre());
|
System.out.println("---Livre : " + ll.getTitre());
|
||||||
break;
|
break;
|
||||||
case 2 :
|
case 2 :
|
||||||
laBibli.addLivre(l1);
|
laBibli.addLivre(ll);
|
||||||
|
laBibli.addLivre(l2);
|
||||||
|
laBibli.addLivre(l3);
|
||||||
|
laBibli.addLivre(l4);
|
||||||
|
laBibli.addLivre(l5);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 3 :
|
case 3 :
|
||||||
for (Livre leLivre : laBibli.getLesLivres()) {
|
for (Livre leLivre : laBibli.getLesLivres()) {
|
||||||
System.out.println("---"+leLivre.toString());
|
if (leLivre.isEmprunte() == true) {
|
||||||
|
System.out.println("---"+ leLivre.getNumero() + " " + leLivre.toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Choisir un livre avec le numéro du livre souhaité");
|
||||||
|
System.out.print("Merci de faire votre choix : ");
|
||||||
|
int choixLivre = sc.nextInt();
|
||||||
|
|
||||||
|
Livre livreChoisi = laBibli.trouverLivreParNumero(choixLivre);
|
||||||
|
if (unUtilisateur.emprunterLivre(livreChoisi) == true) {
|
||||||
|
System.out.print("Validation de l'emprunt");
|
||||||
|
} else {
|
||||||
|
System.out.print("Erreur lors de l'emprunt");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -47,5 +47,12 @@ public class Bibliotheque {
|
|||||||
this.lesLivres = lesLivres;
|
this.lesLivres = lesLivres;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Livre trouverLivreParNumero(int numero) {
|
||||||
|
for (Livre l : lesLivres) {
|
||||||
|
if (l.getNumero() == numero) {
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null; // pas trouvé
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,7 @@ package com.mycompany.bibliotheque.Metier;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class Livre {
|
public class Livre {
|
||||||
|
private int numero;
|
||||||
private String titre;
|
private String titre;
|
||||||
private String auteur;
|
private String auteur;
|
||||||
private String isbn; // ISBN sous forme de chaîne
|
private String isbn; // ISBN sous forme de chaîne
|
||||||
@@ -22,6 +23,18 @@ public class Livre {
|
|||||||
this.emprunte = emprunte;
|
this.emprunte = emprunte;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Livre(int numero, String titre, String auteur, String isbn, Boolean emprunte) {
|
||||||
|
this.numero = numero;
|
||||||
|
this.titre = titre;
|
||||||
|
this.auteur = auteur;
|
||||||
|
this.isbn = isbn;
|
||||||
|
this.emprunte = emprunte;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumero() {
|
||||||
|
return numero;
|
||||||
|
}
|
||||||
|
|
||||||
//getters et setters
|
//getters et setters
|
||||||
public String getTitre() {
|
public String getTitre() {
|
||||||
return titre;
|
return titre;
|
||||||
|
@@ -38,6 +38,7 @@ public class Utilisateur {
|
|||||||
public boolean emprunterLivre(Livre livre) {
|
public boolean emprunterLivre(Livre livre) {
|
||||||
if (emprunts.size() < 3) {
|
if (emprunts.size() < 3) {
|
||||||
emprunts.add(livre);
|
emprunts.add(livre);
|
||||||
|
livre.setEmprunte(false);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user