màj pour version initialeV2
This commit is contained in:
32
src/main/java/com/mycompany/bibliotheque/Bibliotheque.java
Normal file
32
src/main/java/com/mycompany/bibliotheque/Bibliotheque.java
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package com.mycompany.bibliotheque;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*1
|
||||||
|
* @author dthev
|
||||||
|
*/
|
||||||
|
public class Bibliotheque {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
Livre l1 = new Livre("Le secret des secrets","Dan Brown","9782709668385",false);
|
||||||
|
Utilisateur u1 = new Utilisateur("Alice");
|
||||||
|
|
||||||
|
System.out.println("Bienvenue dans la bibliothèque !");
|
||||||
|
System.out.println("1. Afficher un livre");
|
||||||
|
System.out.println("2. Emprunter un livre");
|
||||||
|
System.out.println("Votre choix : ");
|
||||||
|
int choix = sc.nextInt();
|
||||||
|
if (choix == 1) {
|
||||||
|
System.out.println("Livre : " + l1.getTitre());
|
||||||
|
} else if (choix == 2) {
|
||||||
|
boolean ok = Emprunt.effectuerEmprunt(u1, l1);
|
||||||
|
System.out.println(ok ? "Emprunt réussi !" : "Échec de l'emprunt.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
23
src/main/java/com/mycompany/bibliotheque/Emprunt.java
Normal file
23
src/main/java/com/mycompany/bibliotheque/Emprunt.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package com.mycompany.bibliotheque;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author dthev
|
||||||
|
*/
|
||||||
|
public class Emprunt {
|
||||||
|
// TODO: logique métier d'emprunt
|
||||||
|
public static boolean effectuerEmprunt(Utilisateur u, Livre l) {
|
||||||
|
if (l.isEmprunte()) {
|
||||||
|
return false; // déjà emprunté
|
||||||
|
}
|
||||||
|
if (u.getEmprunts().size() >= 3) {
|
||||||
|
return false; // trop de livres empruntés
|
||||||
|
}
|
||||||
|
l.setEmprunte(true);
|
||||||
|
return u.emprunterLivre(l);
|
||||||
|
}
|
||||||
|
}
|
@@ -13,13 +13,16 @@ public class Livre {
|
|||||||
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
|
||||||
|
private Boolean emprunte;
|
||||||
|
|
||||||
public Livre(String titre, String auteur, String isbn) {
|
public Livre(String titre, String auteur, String isbn, Boolean emprunte) {
|
||||||
this.titre = titre;
|
this.titre = titre;
|
||||||
this.auteur = auteur;
|
this.auteur = auteur;
|
||||||
this.isbn = isbn;
|
this.isbn = isbn;
|
||||||
|
this.emprunte = emprunte;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//getters et setters
|
||||||
public String getTitre() {
|
public String getTitre() {
|
||||||
return titre;
|
return titre;
|
||||||
}
|
}
|
||||||
@@ -44,6 +47,15 @@ public class Livre {
|
|||||||
this.isbn = isbn;
|
this.isbn = isbn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isEmprunte() {
|
||||||
|
return emprunte;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmprunte(boolean emprunte) {
|
||||||
|
this.emprunte = emprunte;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
35
src/main/java/com/mycompany/bibliotheque/Utilisateur.java
Normal file
35
src/main/java/com/mycompany/bibliotheque/Utilisateur.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package com.mycompany.bibliotheque;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author dthev
|
||||||
|
*/
|
||||||
|
public class Utilisateur {
|
||||||
|
private String nom;
|
||||||
|
private List<Livre> emprunts;
|
||||||
|
|
||||||
|
public Utilisateur(String nom) {
|
||||||
|
this.nom = nom;
|
||||||
|
this.emprunts = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNom() {
|
||||||
|
return nom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Livre> getEmprunts() {
|
||||||
|
return emprunts;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: ajouter un emprunt si l'utilisateur a moins de 3 livres
|
||||||
|
public boolean emprunterLivre(Livre livre) {
|
||||||
|
return false; // à compléter
|
||||||
|
}
|
||||||
|
}
|
@@ -10,8 +10,8 @@ import static org.junit.Assert.*;
|
|||||||
public class LivreTest {
|
public class LivreTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBookCreation() {
|
public void testCreationLivre() {
|
||||||
Livre b = new Livre("1984", "George Orwell", "1234567890123");
|
Livre b = new Livre("1984", "George Orwell", "1234567890123",false);
|
||||||
assertEquals("1984", b.getTitre());
|
assertEquals("1984", b.getTitre());
|
||||||
assertEquals("George Orwell", b.getAuteur());
|
assertEquals("George Orwell", b.getAuteur());
|
||||||
assertEquals("1234567890123", b.getIsbn());
|
assertEquals("1234567890123", b.getIsbn());
|
||||||
|
Reference in New Issue
Block a user