Compare commits
17 Commits
Delphine
...
a606a72476
Author | SHA1 | Date | |
---|---|---|---|
a606a72476 | |||
9f0f1ae00e | |||
1f44c6ee69 | |||
3f63db1a92 | |||
|
9593ca5fab | ||
6e8f63e2c0 | |||
|
a7b45071cc | ||
|
22bce1d53b | ||
6ec5d152eb | |||
|
f1571ced27 | ||
ca3338fe1a | |||
|
0eac6c497d | ||
|
980fc1cc7c | ||
bec1ca9f04 | |||
fd2f9066b7 | |||
d92fa2649e | |||
62092bb78b |
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/target/
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
*.xml
|
||||
>>>>>>> 6e8f63e2c0b4f89a6f46070511e8ce4223af4bb7
|
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
*/
|
||||
|
||||
package com.mycompany.bibliotheque;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author dthev
|
||||
*/
|
||||
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Bibliotheque {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
Livre l1 = new Livre("1984", 10.0);
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.Contrôle;
|
||||
|
||||
/**
|
||||
* Classe de contrôle de la classe Livre
|
||||
* @author dthev
|
||||
*/
|
||||
public class LivreValide {
|
||||
// 1. ISBN : exactement 13 chiffres
|
||||
public static boolean isValidIsbn(String isbn) {
|
||||
// TODO Emile: implémenter la validation
|
||||
|
||||
boolean valide = true;
|
||||
if(isbn.length() == 13){
|
||||
int i = 0;
|
||||
while (i < 13 && valide) {
|
||||
if(!Character.isDigit(isbn.charAt(i))){
|
||||
valide = false;
|
||||
}else{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
valide = false;
|
||||
}
|
||||
return valide;
|
||||
|
||||
}
|
||||
|
||||
// 2. Titre : pas de balises HTML/JS (<script>, <img>, etc.)
|
||||
public static boolean isValidTitre(String Titre) {
|
||||
// TODO: implémenter la validation
|
||||
return false;
|
||||
}
|
||||
|
||||
// 3. Auteur : non vide et pas de chiffres ou caractères spéciaux
|
||||
public static boolean isValidAuteur(String auteur) {
|
||||
// TODO: implémenter la validation
|
||||
return false;
|
||||
}
|
||||
|
||||
// 4. Titre : longueur maximale 200 caractères
|
||||
public static boolean isLongueurTitreValid(String titre) {
|
||||
// TODO Morgann: implémenter la validation
|
||||
return false;
|
||||
}
|
||||
|
||||
// 5. Titre : non null et au moins 2 caractères
|
||||
public static boolean isContenuTitreValide(String titre) {
|
||||
// TODO Steve: implémenter la validation
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
*/
|
||||
|
||||
package com.mycompany.bibliotheque;
|
||||
|
||||
/**
|
||||
* Classe principale
|
||||
* @author dthev
|
||||
*/
|
||||
|
||||
|
||||
import com.mycompany.bibliotheque.Métier.Bibliotheque;
|
||||
import com.mycompany.bibliotheque.Métier.Emprunt;
|
||||
import com.mycompany.bibliotheque.Métier.Utilisateur;
|
||||
import com.mycompany.bibliotheque.Métier.Livre;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class GestionBibliotheque {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int choix=0;
|
||||
Bibliotheque laBibli = new Bibliotheque();
|
||||
Livre l1 = new Livre("Le secret des secrets","Dan Brown","9782709668385",true);
|
||||
Utilisateur u1 = new Utilisateur("Alice");
|
||||
|
||||
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. Quitter");
|
||||
System.out.print("Merci de faire votre choix : ");
|
||||
choix = sc.nextInt();
|
||||
switch (choix) {
|
||||
case 1 :
|
||||
System.out.println("---Livre : " + l1.getTitre());
|
||||
break;
|
||||
case 2 :
|
||||
laBibli.addLivre(l1);
|
||||
break;
|
||||
case 3 :
|
||||
for (Livre leLivre : laBibli.getLesLivres()) {
|
||||
System.out.println("---"+leLivre.toString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* 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 Livre {
|
||||
private String titre;
|
||||
private double prixHT;
|
||||
private boolean emprunte;
|
||||
|
||||
public Livre(String titre, double prixHT) {
|
||||
this.titre = titre;
|
||||
this.prixHT = prixHT;
|
||||
this.emprunte = false;
|
||||
}
|
||||
|
||||
public String getTitre() {
|
||||
return titre;
|
||||
}
|
||||
|
||||
public double getPrixHT() {
|
||||
return prixHT;
|
||||
}
|
||||
|
||||
public boolean isEmprunte() {
|
||||
return emprunte;
|
||||
}
|
||||
|
||||
public void setEmprunte(boolean emprunte) {
|
||||
this.emprunte = emprunte;
|
||||
}
|
||||
|
||||
// TODO: calculer le prix TTC avec une TVA de 5.5%
|
||||
public double getPrixTTC() {
|
||||
return 0.0; // à compléter
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.Métier;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Classe métier
|
||||
* @author dthev
|
||||
*/
|
||||
public class Bibliotheque {
|
||||
private List<Livre> lesLivres = new ArrayList<>();
|
||||
|
||||
// 5. ISBN doit être unique
|
||||
public boolean addLivre(Livre b) {
|
||||
//ajoute b si valide et si n'existe pas - à écrire
|
||||
lesLivres.add(b);
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<Livre> getLesLivres() {
|
||||
return lesLivres;
|
||||
}
|
||||
|
||||
public void setLesLivres(List<Livre> lesLivres) {
|
||||
this.lesLivres = lesLivres;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -2,7 +2,10 @@
|
||||
* 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;
|
||||
package com.mycompany.bibliotheque.Métier;
|
||||
|
||||
import com.mycompany.bibliotheque.Métier.Utilisateur;
|
||||
import com.mycompany.bibliotheque.Métier.Livre;
|
||||
|
||||
/**
|
||||
*
|
66
src/main/java/com/mycompany/bibliotheque/Métier/Livre.java
Normal file
66
src/main/java/com/mycompany/bibliotheque/Métier/Livre.java
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.Métier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author dthev
|
||||
*/
|
||||
|
||||
public class Livre {
|
||||
private String titre;
|
||||
private String auteur;
|
||||
private String isbn; // ISBN sous forme de chaîne
|
||||
private Boolean emprunte;
|
||||
|
||||
public Livre(String titre, String auteur, String isbn, Boolean emprunte) {
|
||||
this.titre = titre;
|
||||
this.auteur = auteur;
|
||||
this.isbn = isbn;
|
||||
this.emprunte = emprunte;
|
||||
}
|
||||
|
||||
//getters et setters
|
||||
public String getTitre() {
|
||||
return titre;
|
||||
}
|
||||
|
||||
public void setTitre(String titre) {
|
||||
this.titre = titre;
|
||||
}
|
||||
|
||||
public String getAuteur() {
|
||||
return auteur;
|
||||
}
|
||||
|
||||
public void setAuteur(String auteur) {
|
||||
this.auteur = auteur;
|
||||
}
|
||||
|
||||
public String getIsbn() {
|
||||
return isbn;
|
||||
}
|
||||
|
||||
public void setIsbn(String isbn) {
|
||||
this.isbn = isbn;
|
||||
}
|
||||
|
||||
public boolean isEmprunte() {
|
||||
return emprunte;
|
||||
}
|
||||
|
||||
public void setEmprunte(boolean emprunte) {
|
||||
this.emprunte = emprunte;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Livre{" + "titre=" + titre + ", auteur=" + auteur + ", isbn=" + isbn + ", emprunte=" + emprunte + '}';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,13 +2,14 @@
|
||||
* 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;
|
||||
package com.mycompany.bibliotheque.Métier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author dthev
|
||||
*/
|
||||
|
||||
import com.mycompany.bibliotheque.Métier.Livre;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/UnitTests/JUnit4TestClass.java to edit this template
|
||||
*/
|
||||
package com.mycompany.bibliotheque;
|
||||
|
||||
import com.mycompany.bibliotheque.Métier.Bibliotheque;
|
||||
import com.mycompany.bibliotheque.Métier.Livre;
|
||||
import java.util.List;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author dthev
|
||||
*/
|
||||
public class BibliothequeTest {
|
||||
|
||||
public BibliothequeTest() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of addLivre method, of class Bibliotheque.
|
||||
*/
|
||||
@Test
|
||||
public void testAddLivre() {
|
||||
System.out.println("addLivre");
|
||||
Livre b = null;
|
||||
Bibliotheque instance = new Bibliotheque();
|
||||
boolean expResult = false;
|
||||
boolean result = instance.addLivre(b);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of getLesLivres method, of class Bibliotheque.
|
||||
*/
|
||||
@Test
|
||||
public void testGetLesLivres() {
|
||||
System.out.println("getLesLivres");
|
||||
Bibliotheque instance = new Bibliotheque();
|
||||
List<Livre> expResult = null;
|
||||
List<Livre> result = instance.getLesLivres();
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of setLesLivres method, of class Bibliotheque.
|
||||
*/
|
||||
@Test
|
||||
public void testSetLesLivres() {
|
||||
System.out.println("setLesLivres");
|
||||
List<Livre> lesLivres = null;
|
||||
Bibliotheque instance = new Bibliotheque();
|
||||
instance.setLesLivres(lesLivres);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
}
|
@@ -4,49 +4,20 @@
|
||||
*/
|
||||
package com.mycompany.bibliotheque;
|
||||
|
||||
import com.mycompany.bibliotheque.Métier.Livre;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class LivreTest {
|
||||
|
||||
private Livre livre;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
// Création d'un livre avant chaque test
|
||||
livre = new Livre("Java Basics", 20.0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTitre() {
|
||||
assertEquals("pb titre","Java Basic", livre.getTitre());
|
||||
}
|
||||
public void testCreationLivre() {
|
||||
Livre b = new Livre("1984", "George Orwell", "1234567890123", false);
|
||||
|
||||
@Test
|
||||
public void testGetPrixHT() {
|
||||
// Vérification du prix HT arrondi à 3 décimales
|
||||
//assertEquals(20.0, livre.getPrixHT(), 0.001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsEmprunte() {
|
||||
// Par défaut, le livre n'est pas emprunté
|
||||
assertFalse(livre.isEmprunte());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetEmprunte() {
|
||||
livre.setEmprunte(true);
|
||||
assertTrue(livre.isEmprunte());
|
||||
livre.setEmprunte(false);
|
||||
assertFalse(livre.isEmprunte());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPrixTTC() {
|
||||
// Calcul du prix TTC avec TVA 5.5% arrondi à 2 décimales
|
||||
//assertEquals(21.1, livre.getPrixTTC(), 0.01);
|
||||
}
|
||||
assertNotNull(b);
|
||||
assertEquals("1984", b.getTitre());
|
||||
assertEquals("George Orwel", b.getAuteur()); // corrigé
|
||||
assertEquals("1234567890123", b.getIsbn());
|
||||
assertFalse(b.isEmprunte()); // si la méthode existe
|
||||
}
|
||||
}
|
146
src/test/java/com/mycompany/bibliotheque/LivreValideTest.java
Normal file
146
src/test/java/com/mycompany/bibliotheque/LivreValideTest.java
Normal file
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/UnitTests/JUnit4TestClass.java to edit this template
|
||||
*/
|
||||
package com.mycompany.bibliotheque;
|
||||
|
||||
import com.mycompany.bibliotheque.Contrôle.LivreValide;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author dthev
|
||||
*/
|
||||
public class LivreValideTest {
|
||||
|
||||
public LivreValideTest() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of isValidIsbn method, of class LivreValide.
|
||||
* @author Emile
|
||||
*/
|
||||
@Test
|
||||
public void testIsValidIsbn() {
|
||||
System.out.println("isValidIsbn");
|
||||
|
||||
|
||||
//Test 1 : un isbn avec moins de 13 carractères
|
||||
System.out.println("Test1 : un isbn avec moins de 13 carractères");
|
||||
String isbn1 = "1234568912";
|
||||
boolean expResult1 = false;
|
||||
boolean result1 = LivreValide.isValidIsbn(isbn1);
|
||||
assertEquals("Le nombre de carractère est censé est trop petit",expResult1, result1);
|
||||
assertFalse("Trop petit",LivreValide.isValidIsbn(isbn1));
|
||||
System.out.println("Le test1 est validé");
|
||||
System.out.println("--------------------------------------------------");
|
||||
System.out.println(" ");
|
||||
|
||||
//Test2 : lettre dans l'isbn
|
||||
System.out.println("Test2 : lettre dans l'isbn");
|
||||
String isbn2 = "123456789ABC2";
|
||||
boolean expResult2 = false;
|
||||
boolean result2 = LivreValide.isValidIsbn(isbn2);
|
||||
assertEquals("Les alphas ne sont pas autorisés", expResult2, result2);
|
||||
System.out.println("Le test2 est validé");
|
||||
System.out.println("--------------------------------------------------");
|
||||
System.out.println(" ");
|
||||
|
||||
//Test3 : mauvais nombre de carratère 15
|
||||
System.out.println("Test3: isbn comportant plus de 13 chiffres");
|
||||
String isbn3 = "1234568912123568";
|
||||
boolean expResult3 = false;
|
||||
boolean result3 = LivreValide.isValidIsbn(isbn3);
|
||||
assertEquals("Le nombre de carractère est censé est trop grand",expResult3, result3);
|
||||
System.out.println("Le test3 est validé");
|
||||
System.out.println("--------------------------------------------------");
|
||||
System.out.println(" ");
|
||||
|
||||
//Test4 : Un isbn valide
|
||||
System.out.println("Test4: Un isbn valide");
|
||||
String isbn4 = "1234568912126";
|
||||
boolean expResult4 = true;
|
||||
boolean result4 = LivreValide.isValidIsbn(isbn4);
|
||||
assertEquals("L'isbn est censé être valide",expResult4, result4);
|
||||
System.out.println("Le test4 est validé");
|
||||
System.out.println("--------------------------------------------------");
|
||||
System.out.println(" ");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of isValidTitre method, of class LivreValide.
|
||||
* @author Salomé/Emile
|
||||
*/
|
||||
@Test
|
||||
public void testIsValidTitre() {
|
||||
System.out.println("isValidTitre");
|
||||
String Titre = "";
|
||||
boolean expResult = false;
|
||||
boolean result = LivreValide.isValidTitre(Titre);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of isValidAuteur method, of class LivreValide.
|
||||
* @author Medhi/Steve
|
||||
*/
|
||||
@Test
|
||||
public void testIsValidAuteur() {
|
||||
System.out.println("isValidAuteur");
|
||||
String auteur = "";
|
||||
boolean expResult = false;
|
||||
boolean result = LivreValide.isValidAuteur(auteur);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of isLongueurTitreValid method, of class LivreValide.
|
||||
* @author Morgann
|
||||
*/
|
||||
@Test
|
||||
public void testIsLongueurTitreValid() {
|
||||
System.out.println("isLongueurTitreValid");
|
||||
String titre = "";
|
||||
boolean expResult = false;
|
||||
boolean result = LivreValide.isLongueurTitreValid(titre);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIsContenuTitreValid() {
|
||||
System.out.println("isLongueurTitreValid");
|
||||
String titre = "";
|
||||
boolean expResult = false;
|
||||
boolean result = LivreValide.isLongueurTitreValid(titre);
|
||||
}
|
||||
/**
|
||||
* Test of isTitreValid method, of class LivreValide.
|
||||
* @author Steve
|
||||
*/
|
||||
@Test
|
||||
public void testIsContenuTitreValide() {
|
||||
System.out.println("isTitreValid");
|
||||
String titre = "";
|
||||
boolean expResult = false;
|
||||
boolean result = LivreValide.isContenuTitreValide(titre);
|
||||
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
}
|
@@ -4,6 +4,8 @@
|
||||
*/
|
||||
package com.mycompany.bibliotheque;
|
||||
|
||||
import com.mycompany.bibliotheque.Métier.Utilisateur;
|
||||
import com.mycompany.bibliotheque.Métier.Livre;
|
||||
import java.util.List;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
Reference in New Issue
Block a user