Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
2c79daa4b9 |
@@ -110,7 +110,7 @@ public class LivreValide {
|
||||
i++;
|
||||
System.out.println(i+". "+unLivre.getTitre());
|
||||
}
|
||||
System.out.print("Merci de faire le choix du livre à restituer: ");
|
||||
System.out.print("Merci de faire votre choix : ");
|
||||
int choix = sc.nextInt();
|
||||
Livre leLivre = user.getEmprunts().get(choix-1);
|
||||
|
||||
|
@@ -10,7 +10,6 @@ package com.mycompany.bibliotheque;
|
||||
*/
|
||||
|
||||
|
||||
import com.mycompany.bibliotheque.Controle.LivreValide;
|
||||
import com.mycompany.bibliotheque.Metier.Bibliotheque;
|
||||
import com.mycompany.bibliotheque.Metier.Emprunt;
|
||||
import com.mycompany.bibliotheque.Metier.Utilisateur;
|
||||
@@ -24,45 +23,54 @@ public class GestionBibliotheque {
|
||||
int choix=0;
|
||||
Bibliotheque laBibli = new Bibliotheque();
|
||||
ArrayList<Livre> mesLivres = new ArrayList<>();
|
||||
Livre l1 = new Livre("Le secret des secrets","Dan Brown","9782709668385",true);
|
||||
mesLivres.add(l1);
|
||||
Utilisateur u1 = new Utilisateur("Alice", mesLivres);
|
||||
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));
|
||||
|
||||
System.out.println("Bienvenue dans la bibliothèque !");
|
||||
while (choix!=4){
|
||||
System.out.println("1. Afficher un livre");
|
||||
System.out.println("2. Ajouter un livre");
|
||||
System.out.println("3. Afficher les livres");
|
||||
System.out.println("4. Restituer un livre");
|
||||
System.out.println("5. Quitter");
|
||||
System.out.println("4. Quitter");
|
||||
System.out.print("Merci de faire votre choix : ");
|
||||
choix = sc.nextInt();
|
||||
switch (choix) {
|
||||
case 1 :
|
||||
System.out.println("---Livre : " + l1.getTitre());
|
||||
System.out.println("---Livre : " + ll.getTitre());
|
||||
break;
|
||||
case 2 :
|
||||
laBibli.addLivre(l1);
|
||||
laBibli.addLivre(ll);
|
||||
laBibli.addLivre(l2);
|
||||
laBibli.addLivre(l3);
|
||||
laBibli.addLivre(l4);
|
||||
laBibli.addLivre(l5);
|
||||
|
||||
break;
|
||||
case 3 :
|
||||
for (Livre leLivre : laBibli.getLesLivres()) {
|
||||
System.out.println("---"+leLivre.toString());
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
boolean restitution = LivreValide.retourLivre(u1);
|
||||
String message = "";
|
||||
|
||||
if (restitution) {
|
||||
message += "Le livre a été restitué !\n";
|
||||
message += "\\nVous avez désormais "+u1.getEmprunts().size()+" livres empruntés sur 3 !\n";
|
||||
message += "Merci, "+u1.getNom()+", d'avoir emprunté chez nous !";
|
||||
|
||||
} else {
|
||||
message += "Le livre n'a pas été restitué.";
|
||||
if (leLivre.isEmprunte() == true) {
|
||||
System.out.println("---"+ leLivre.getNumero() + " " + leLivre.toString());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(message);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -47,5 +47,12 @@ public class Bibliotheque {
|
||||
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 {
|
||||
private int numero;
|
||||
private String titre;
|
||||
private String auteur;
|
||||
private String isbn; // ISBN sous forme de chaîne
|
||||
@@ -21,6 +22,18 @@ public class Livre {
|
||||
this.isbn = isbn;
|
||||
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
|
||||
public String getTitre() {
|
||||
|
@@ -38,6 +38,7 @@ public class Utilisateur {
|
||||
public boolean emprunterLivre(Livre livre) {
|
||||
if (emprunts.size() < 3) {
|
||||
emprunts.add(livre);
|
||||
livre.setEmprunte(false);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user