This commit is contained in:
36
pom.xml
Normal file
36
pom.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
||||
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.mycompany</groupId>
|
||||
<artifactId>bibliotheque</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<!-- Dépendances du projet -->
|
||||
<dependencies>
|
||||
<!-- JUnit 4 pour les tests -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<!-- Configuration du build -->
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- Maven Surefire Plugin pour exécuter les tests -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.1.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
33
src/main/java/com/mycompany/bibliotheque/Bibliotheque.java
Normal file
33
src/main/java/com/mycompany/bibliotheque/Bibliotheque.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.");
|
||||
}
|
||||
}
|
||||
}
|
25
src/main/java/com/mycompany/bibliotheque/Emprunt.java
Normal file
25
src/main/java/com/mycompany/bibliotheque/Emprunt.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
45
src/main/java/com/mycompany/bibliotheque/Livre.java
Normal file
45
src/main/java/com/mycompany/bibliotheque/Livre.java
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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
|
||||
}
|
||||
}
|
||||
|
||||
|
36
src/main/java/com/mycompany/bibliotheque/Utilisateur.java
Normal file
36
src/main/java/com/mycompany/bibliotheque/Utilisateur.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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
|
||||
}
|
||||
}
|
52
src/test/java/com/mycompany/bibliotheque/LivreTest.java
Normal file
52
src/test/java/com/mycompany/bibliotheque/LivreTest.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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 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());
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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 java.util.List;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author dthev
|
||||
*/
|
||||
public class UtilisateurTest {
|
||||
|
||||
public UtilisateurTest() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of getNom method, of class Utilisateur.
|
||||
*/
|
||||
@Test
|
||||
public void testGetNom() {
|
||||
System.out.println("getNom");
|
||||
Utilisateur instance = null;
|
||||
String expResult = "";
|
||||
String result = instance.getNom();
|
||||
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 getEmprunts method, of class Utilisateur.
|
||||
*/
|
||||
@Test
|
||||
public void testGetEmprunts() {
|
||||
System.out.println("getEmprunts");
|
||||
Utilisateur instance = null;
|
||||
List<Livre> expResult = null;
|
||||
List<Livre> result = instance.getEmprunts();
|
||||
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 emprunterLivre method, of class Utilisateur.
|
||||
*/
|
||||
@Test
|
||||
public void testEmprunterLivre() {
|
||||
System.out.println("emprunterLivre");
|
||||
Livre livre = null;
|
||||
Utilisateur instance = null;
|
||||
boolean expResult = false;
|
||||
boolean result = instance.emprunterLivre(livre);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user