Compare commits
No commits in common. "master" and "dt" have entirely different histories.
@ -19,20 +19,10 @@ public class Test {
|
|||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Entreprise lEntreprise=new Entreprise("MusicAndCo");
|
Entreprise lEntreprise=new Entreprise("MusicAndCo");
|
||||||
Commande laCommande1 = new Commande(1,1,"12/09/2024");
|
Commande laCommande = new Commande(1,1,"12/09/2024");
|
||||||
|
lEntreprise.ajouterCommande(laCommande);
|
||||||
|
|
||||||
//ajouter des instruments de l'entreprise à la commande
|
//ajouter 3 piano droit et 2 violon alto dans la commande
|
||||||
|
|
||||||
//affecter la commande à l'entreprise si la comamnde est possible
|
|
||||||
lEntreprise.ajouterCommande(laCommande1);
|
|
||||||
|
|
||||||
//créer une autre commande
|
|
||||||
|
|
||||||
|
|
||||||
//rechercher et afficher une commande
|
|
||||||
|
|
||||||
|
|
||||||
//supprimer une des 2 commande
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,145 +1,123 @@
|
|||||||
/*
|
/*
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
* 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
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package métiers;
|
package métiers;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author ilona
|
* @author ilona
|
||||||
*/
|
*/
|
||||||
public class Commande {
|
public class Commande {
|
||||||
|
|
||||||
private int noCom, noVendeur;
|
private int noCom, noVendeur;
|
||||||
private String dateCom;
|
private String dateCom;
|
||||||
|
|
||||||
|
|
||||||
private final HashMap<Instrument, Integer> lesLignes = new HashMap<>();
|
private final HashMap<Instrument, Integer> lesLignes = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
public Commande(int noCom, int noVendeur, String dateCom) {
|
public Commande(int noCom, int noVendeur, String dateCom) {
|
||||||
this.noCom = noCom;
|
this.noCom = noCom;
|
||||||
this.noVendeur = noVendeur;
|
this.noVendeur = noVendeur;
|
||||||
this.dateCom = dateCom;
|
this.dateCom = dateCom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ajoute une quantité donnée d'un instrument à la commande
|
* Ajoute une quantité donnée d'un instrument à la commande
|
||||||
* @param unInstrument instrument à ajouter
|
* @param unInstrument instrument à ajouter
|
||||||
* @param qte quantité à ajouter
|
* @param qte quantité à ajouter
|
||||||
* @return true si l'ajout est bon
|
* @return true si l'ajout est bon
|
||||||
*/
|
*/
|
||||||
public boolean ajouter(Instrument unInstrument, int qte){
|
public boolean ajouter(Instrument unInstrument, int qte){
|
||||||
|
//il faut gérer l'ajout d'un instrument existant dans la commande, ce sera une mise à jour de la ligne
|
||||||
//il faut empêcher l'ajout d'une ligne avec une quantité à 0
|
//il faut empêcher l'ajout d'une ligne avec une quantité à 0
|
||||||
//bien s'assurer que le stock est suffisant
|
//bien s'assurer que le stock est suffisant
|
||||||
boolean ajoutOK=false;
|
boolean ajoutOK;
|
||||||
if(qte!=0){
|
int qteDisponible = unInstrument.getQteStock();
|
||||||
//ajout d'un instrument existant dans la commande, ce sera une mise à jour de la ligne
|
if (qteDisponible<qte){
|
||||||
if (lesLignes.containsKey(unInstrument))//l'instrument existe
|
ajoutOK = false;
|
||||||
{
|
}else {
|
||||||
//récupération de la quantité en stock
|
ajoutOK = true;
|
||||||
int oldQte=unInstrument.getQteStock();
|
lesLignes.put(unInstrument,qte);
|
||||||
//réaffectation dans le stock de la quantité commandée
|
unInstrument.setQteStock(qteDisponible-qte);
|
||||||
int qteStock=oldQte+ this.getLesLignes().get(unInstrument);
|
}
|
||||||
unInstrument.setQteStock(qteStock);
|
return ajoutOK;
|
||||||
//suppression ligne commande
|
}
|
||||||
lesLignes.remove(unInstrument);
|
/**
|
||||||
//nouvel ajout
|
* Supprimer un instrument de la commande
|
||||||
this.ajouter(unInstrument,qte);
|
* @param unInstrument instrument à supprimer
|
||||||
|
* @return true si la suppression est effectuée
|
||||||
}
|
*/
|
||||||
else //nouvel instrument
|
public boolean supprimer(Instrument unInstrument){
|
||||||
{
|
//lesLignes.remove(unInstrument);
|
||||||
//on s'assure qu'il y a assez de stock pour la commande
|
boolean suppOK;
|
||||||
|
if (lesLignes.containsKey(unInstrument) == true){
|
||||||
int qteDisponible = unInstrument.getQteStock();
|
suppOK = true;
|
||||||
if (qteDisponible<qte){
|
lesLignes.remove(unInstrument);
|
||||||
ajoutOK = false;
|
} else {
|
||||||
}else {
|
suppOK = false;
|
||||||
ajoutOK = true;
|
}
|
||||||
lesLignes.put(unInstrument,qte);
|
return suppOK;
|
||||||
//màj qté stock pour déduire la qté commandée
|
}
|
||||||
unInstrument.setQteStock(qteDisponible-qte);
|
|
||||||
}
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
}
|
|
||||||
}
|
public int getNoCom() {
|
||||||
return ajoutOK;
|
return noCom;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Supprimer un instrument de la commande
|
public int getNoVendeur() {
|
||||||
* @param unInstrument instrument à supprimer
|
return noVendeur;
|
||||||
* @return true si la suppression est effectuée
|
}
|
||||||
*/
|
|
||||||
public boolean supprimer(Instrument unInstrument){
|
public String getDateCom() {
|
||||||
//lesLignes.remove(unInstrument);
|
return dateCom;
|
||||||
boolean suppOK;
|
}
|
||||||
if (lesLignes.containsKey(unInstrument) == true){
|
|
||||||
suppOK = true;
|
public HashMap<Instrument, Integer> getLesLignes() {
|
||||||
lesLignes.remove(unInstrument);
|
return lesLignes;
|
||||||
} else {
|
}
|
||||||
suppOK = false;
|
|
||||||
}
|
|
||||||
return suppOK;
|
public void setNoCom(int noCom) {
|
||||||
}
|
this.noCom = noCom;
|
||||||
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
public void setNoVendeur(int noVendeur) {
|
||||||
public int getNoCom() {
|
this.noVendeur = noVendeur;
|
||||||
return noCom;
|
}
|
||||||
}
|
|
||||||
|
public void setDateCom(String dateCom) {
|
||||||
public int getNoVendeur() {
|
this.dateCom = dateCom;
|
||||||
return noVendeur;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
public String getDateCom() {
|
public boolean equals(Object obj) {
|
||||||
return dateCom;
|
if (this == obj) {
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
public HashMap<Instrument, Integer> getLesLignes() {
|
if (obj == null) {
|
||||||
return lesLignes;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (getClass() != obj.getClass()) {
|
||||||
|
return false;
|
||||||
public void setNoCom(int noCom) {
|
}
|
||||||
this.noCom = noCom;
|
final Commande other = (Commande) obj;
|
||||||
}
|
if (this.noCom != other.noCom) {
|
||||||
|
return false;
|
||||||
public void setNoVendeur(int noVendeur) {
|
}
|
||||||
this.noVendeur = noVendeur;
|
if (this.noVendeur != other.noVendeur) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
public void setDateCom(String dateCom) {
|
return Objects.equals(this.dateCom, other.dateCom);
|
||||||
this.dateCom = dateCom;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
}
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (obj == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (getClass() != obj.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final Commande other = (Commande) obj;
|
|
||||||
if (this.noCom != other.noCom) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (this.noVendeur != other.noVendeur) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return Objects.equals(this.dateCom, other.dateCom);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -15,12 +15,12 @@ import métiers.Instrument;
|
|||||||
public class Entreprise {
|
public class Entreprise {
|
||||||
private String raisonSociale;
|
private String raisonSociale;
|
||||||
private ArrayList<Commande> lesCommandes = new ArrayList<>();
|
private ArrayList<Commande> lesCommandes = new ArrayList<>();
|
||||||
private ArrayList<Instrument> lesInstruments = new ArrayList<>();
|
|
||||||
|
|
||||||
public Entreprise(String raisonSociale) {
|
public Entreprise(String raisonSociale) {
|
||||||
this.raisonSociale = raisonSociale;
|
this.raisonSociale = raisonSociale;
|
||||||
|
|
||||||
Instrument instr1=new Instrument(23,"Piano droit",3, 8300f);
|
ArrayList<Instrument> lesInstruments = new ArrayList<>();
|
||||||
|
Instrument instr1=new Instrument(23,"Piano droit",3, 8300f);
|
||||||
Instrument instr2=new Instrument(54,"Violon Alto",5, 105f);
|
Instrument instr2=new Instrument(54,"Violon Alto",5, 105f);
|
||||||
Instrument instr3=new Instrument(67,"Guitare Classique",8, 575f);
|
Instrument instr3=new Instrument(67,"Guitare Classique",8, 575f);
|
||||||
lesInstruments.add(instr3);
|
lesInstruments.add(instr3);
|
||||||
|
@ -5,7 +5,9 @@
|
|||||||
package métiers;
|
package métiers;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -16,21 +18,19 @@ public class CommandeTest {
|
|||||||
public CommandeTest() {
|
public CommandeTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of ajouter method, of class Commande.
|
* Test of ajouter method, of class Commande.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testAjouter() {
|
public void testAjouter() {
|
||||||
Instrument instr1=new Instrument(1,"Piano",10, 8300f);
|
Instrument instr1=new Instrument(1,"Piano",10, 8300f);
|
||||||
Instrument instr2=new Instrument(2,"Violon",9, 105f);
|
Instrument instr2=new Instrument(2,"Violon",9, 105f);
|
||||||
Instrument instr3=new Instrument(3,"piano",8, 105f);
|
|
||||||
Commande laCommande = new Commande(1,1,"12/09/2024");
|
Commande laCommande = new Commande(1,1,"12/09/2024");
|
||||||
System.out.println("ajouter");
|
System.out.println("ajouter");
|
||||||
//cas 0
|
|
||||||
boolean ajoutRes= laCommande.ajouter(instr1, 2);
|
boolean ajoutRes= laCommande.ajouter(instr1, 2);
|
||||||
boolean ajoutAttendu = true;
|
boolean ajoutAttendu = true;
|
||||||
System.out.println("cas0 : cas normal, ajout une ligne de commande");
|
System.out.println("cas0 : cas normal, ajout une ligne de commande");
|
||||||
@ -42,80 +42,32 @@ public class CommandeTest {
|
|||||||
int qteAttendu=2;
|
int qteAttendu=2;
|
||||||
assertEquals("Test0 quantite",qteRes, qteAttendu);
|
assertEquals("Test0 quantite",qteRes, qteAttendu);
|
||||||
|
|
||||||
//cas 1
|
|
||||||
System.out.println("Cas1 : ajout autre ligne de commande");
|
System.out.println("Cas1 : ajout autre ligne de commande");
|
||||||
laCommande.ajouter(instr2, 6);
|
laCommande.ajouter(instr2, 6);
|
||||||
int tailleR=laCommande.getLesLignes().size();
|
int tailleR=laCommande.getLesLignes().size();
|
||||||
int tailleAttendue=2;
|
int tailleAttendue=2;
|
||||||
assertEquals("Test1 taille",tailleAttendue,tailleR);
|
assertEquals("Test1 taille",tailleAttendue,tailleR);
|
||||||
|
|
||||||
//Cas2
|
|
||||||
System.out.println("Cas2 : màj quantité commandée d'une ligne existante");
|
System.out.println("Cas2 : màj quantité commandée d'une ligne existante");
|
||||||
laCommande.ajouter(instr2, 5);
|
laCommande.ajouter(instr2, 5);
|
||||||
stockRes=instr2.getQteStock();
|
stockRes=instr2.getQteStock();
|
||||||
stockAttendu=4;
|
stockAttendu=4;
|
||||||
assertEquals("test2 stock",stockAttendu,stockRes );
|
assertEquals("test2 stock",stockAttendu,stockRes );
|
||||||
|
|
||||||
qteRes=laCommande.getLesLignes().get(instr2);
|
/*qteRes=laCommande.getLesLignes().get(instr2);
|
||||||
qteAttendu=5;
|
qteAttendu=5;
|
||||||
assertEquals("Test2 quantite", qteAttendu,qteRes);
|
assertEquals("Test2 quantite", qteAttendu,qteRes);*/
|
||||||
|
|
||||||
/*INES*/
|
/*INES*/
|
||||||
System.out.println("Cas3 : ajout nouvelle ligne avec quantité > stock");
|
System.out.println("Cas3 : ajout nouvelle ligne avec quantité > stock");
|
||||||
boolean test= laCommande.ajouter(instr3, 12);
|
|
||||||
stockRes=instr3.getQteStock();
|
|
||||||
stockAttendu=8;
|
|
||||||
boolean testResultExpected=false;
|
|
||||||
|
|
||||||
assertEquals("test3 stock",stockAttendu,stockRes );
|
|
||||||
assertEquals("La méthode ajouter retourne false",testResultExpected,test );
|
|
||||||
|
|
||||||
System.out.println("Nombre de ligne dans le dictionnaire: "+laCommande.getLesLignes().size());
|
|
||||||
System.out.println("Résultat de la méthode ajouter: " + test);
|
|
||||||
|
|
||||||
/*MAISSANE*/
|
/*MAISSANE*/
|
||||||
System.out.println("Cas4 : ajout nouvelle ligne avec quantité 0");
|
System.out.println("Cas4 : ajout nouvelle ligne avec quantité 0");
|
||||||
System.out.println("Cas4 : ajout nouvelle ligne avec quantité 0");
|
|
||||||
boolean AjouterObtenu=laCommande.ajouter(instr3, 0);
|
|
||||||
boolean AjouterA= false;
|
|
||||||
assertEquals("Test4 ajout 0 instr3",AjouterA,AjouterObtenu);
|
|
||||||
int lignes=laCommande.getLesLignes().size();
|
|
||||||
int nbLigneAttendu = 2;
|
|
||||||
assertEquals("Test4 taille",nbLigneAttendu,lignes);
|
|
||||||
qteRes=laCommande.getLesLignes().get(instr3);
|
|
||||||
qteAttendu=0;
|
|
||||||
assertEquals("Test4 quantite", qteAttendu,qteRes);
|
|
||||||
|
|
||||||
|
|
||||||
/*MORGANN*/
|
/*MORGANN*/
|
||||||
System.out.println("Cas5 : mise à 0 quantité commandée d'une ligne existante");
|
System.out.println("Cas5 : mise à 0 quantité commandée d'une ligne existante");
|
||||||
laCommande.ajouter(instr2, 0);
|
/*INES*/
|
||||||
stockRes=instr2.getQteStock();
|
|
||||||
stockAttendu=9;
|
|
||||||
assertEquals("test5 stock",stockAttendu,stockRes );
|
|
||||||
tailleR=laCommande.getLesLignes().size();
|
|
||||||
tailleAttendue=2;
|
|
||||||
assertEquals("Test1 taille",tailleAttendue,tailleR);
|
|
||||||
/*ILONA*/
|
|
||||||
System.out.println("Cas6 : màj d'une ligne existante avec qté>stock");
|
System.out.println("Cas6 : màj d'une ligne existante avec qté>stock");
|
||||||
System.out.println("Cas6 : màj d'une ligne existante avec qté>stock");
|
|
||||||
boolean resultatMethode = laCommande.ajouter(instr1, 12);
|
|
||||||
boolean resultatMethodeAttendu=false;
|
|
||||||
assertEquals("test6 mise à jour",resultatMethodeAttendu,resultatMethode);
|
|
||||||
stockRes=instr1.getQteStock();
|
|
||||||
stockAttendu=2;
|
|
||||||
assertEquals("test6 stock",stockAttendu,stockRes );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertEquals(String test1_taille, int tailleAttendue, int tailleR) {
|
|
||||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertEquals(String la_méthode_ajouter_retourne_false, boolean testResultExpected, boolean test) {
|
|
||||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of supprimer method, of class Commande.
|
* Test of supprimer method, of class Commande.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user