Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
02873d405b |
@@ -110,7 +110,7 @@ public class LivreValide {
|
|||||||
i++;
|
i++;
|
||||||
System.out.println(i+". "+unLivre.getTitre());
|
System.out.println(i+". "+unLivre.getTitre());
|
||||||
}
|
}
|
||||||
System.out.print("Merci de faire votre choix : ");
|
System.out.print("Merci de faire le choix du livre à restituer: ");
|
||||||
int choix = sc.nextInt();
|
int choix = sc.nextInt();
|
||||||
Livre leLivre = user.getEmprunts().get(choix-1);
|
Livre leLivre = user.getEmprunts().get(choix-1);
|
||||||
|
|
||||||
|
@@ -10,6 +10,7 @@ package com.mycompany.bibliotheque;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
import com.mycompany.bibliotheque.Controle.LivreValide;
|
||||||
import com.mycompany.bibliotheque.Metier.Bibliotheque;
|
import com.mycompany.bibliotheque.Metier.Bibliotheque;
|
||||||
import com.mycompany.bibliotheque.Metier.Emprunt;
|
import com.mycompany.bibliotheque.Metier.Emprunt;
|
||||||
import com.mycompany.bibliotheque.Metier.Utilisateur;
|
import com.mycompany.bibliotheque.Metier.Utilisateur;
|
||||||
@@ -23,54 +24,45 @@ 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<>();
|
||||||
Utilisateur unUtilisateur = new Utilisateur("Emile", mesLivres);
|
Livre l1 = new Livre("Le secret des secrets","Dan Brown","9782709668385",true);
|
||||||
Livre ll = new Livre(1,"Le secret des secrets","Dan Brown","9782709668385",true);
|
mesLivres.add(l1);
|
||||||
Livre l2 = new Livre(2,"Le secret des secrets","Dan Brown","9772709668385",true);
|
Utilisateur u1 = new Utilisateur("Alice", mesLivres);
|
||||||
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 !");
|
System.out.println("Bienvenue dans la bibliothèque !");
|
||||||
while (choix!=4){
|
while (choix!=4){
|
||||||
System.out.println("1. Afficher un livre");
|
System.out.println("1. Afficher un livre");
|
||||||
System.out.println("2. Ajouter un livre");
|
System.out.println("2. Ajouter un livre");
|
||||||
System.out.println("3. Afficher les livres");
|
System.out.println("3. Afficher les livres");
|
||||||
System.out.println("4. Quitter");
|
System.out.println("4. Restituer un livre");
|
||||||
|
System.out.println("5. Quitter");
|
||||||
System.out.print("Merci de faire votre choix : ");
|
System.out.print("Merci de faire votre choix : ");
|
||||||
choix = sc.nextInt();
|
choix = sc.nextInt();
|
||||||
switch (choix) {
|
switch (choix) {
|
||||||
case 1 :
|
case 1 :
|
||||||
System.out.println("---Livre : " + ll.getTitre());
|
System.out.println("---Livre : " + l1.getTitre());
|
||||||
break;
|
break;
|
||||||
case 2 :
|
case 2 :
|
||||||
laBibli.addLivre(ll);
|
laBibli.addLivre(l1);
|
||||||
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()) {
|
||||||
if (leLivre.isEmprunte() == true) {
|
System.out.println("---"+leLivre.toString());
|
||||||
System.out.println("---"+ leLivre.getNumero() + " " + leLivre.toString());
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
System.out.println("Choisir un livre avec le numéro du livre souhaité");
|
case 4:
|
||||||
System.out.print("Merci de faire votre choix : ");
|
boolean restitution = LivreValide.retourLivre(u1);
|
||||||
int choixLivre = sc.nextInt();
|
String message = "";
|
||||||
|
|
||||||
Livre livreChoisi = laBibli.trouverLivreParNumero(choixLivre);
|
if (restitution) {
|
||||||
if (unUtilisateur.emprunterLivre(livreChoisi) == true) {
|
message += "Le livre a été restitué !\n";
|
||||||
System.out.print("Validation de l'emprunt");
|
message += "\\nVous avez désormais "+u1.getEmprunts().size()+" livres empruntés sur 3 !\n";
|
||||||
|
message += "Merci, "+u1.getNom()+", d'avoir emprunté chez nous !";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
System.out.print("Erreur lors de l'emprunt");
|
message += "Le livre n'a pas été restitué.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -47,12 +47,5 @@ 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,7 +10,6 @@ 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,18 +21,6 @@ public class Livre {
|
|||||||
this.isbn = isbn;
|
this.isbn = isbn;
|
||||||
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() {
|
||||||
|
@@ -38,7 +38,6 @@ 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