Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
a1d5485025 | |||
09a7279d52 | |||
c000fb78ee | |||
b109399da5 | |||
08e7254265 | |||
6bcc94486f | |||
9e6a9cc867 | |||
8dc9d9d385 | |||
e4956996d6 | |||
6ed7fb09f2 | |||
45a93f086a | |||
0680043384 | |||
b02b4b8bcf |
@ -75,7 +75,7 @@ jlink.additionalmodules=
|
|||||||
jlink.additionalparam=
|
jlink.additionalparam=
|
||||||
jlink.launcher=true
|
jlink.launcher=true
|
||||||
jlink.launcher.name=MusicAndCo
|
jlink.launcher.name=MusicAndCo
|
||||||
main.class=Test
|
main.class=MusicAndCo.Test
|
||||||
manifest.file=manifest.mf
|
manifest.file=manifest.mf
|
||||||
meta.inf.dir=${src.dir}/META-INF
|
meta.inf.dir=${src.dir}/META-INF
|
||||||
mkdist.disabled=false
|
mkdist.disabled=false
|
||||||
|
90
src/MusicAndCo/Test.java
Normal file
90
src/MusicAndCo/Test.java
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
package MusicAndCo;
|
||||||
|
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import métiers.Commande;
|
||||||
|
import métiers.Entreprise;
|
||||||
|
import métiers.Instrument;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author sio
|
||||||
|
*/
|
||||||
|
public class Test {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param args the command line arguments
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner lectureClavier=new Scanner(System.in);
|
||||||
|
DateFormat format = new SimpleDateFormat("dd/MM/yyyy");
|
||||||
|
Date date = new Date();
|
||||||
|
Entreprise lEntreprise=new Entreprise("MusicAndCo");
|
||||||
|
Commande laCommande1 = new Commande(1,1,format.format(date));
|
||||||
|
Commande laCommande2 = new Commande(2,1,format.format(date));
|
||||||
|
|
||||||
|
System.out.println("Bienvenue dans ma boutique :" + lEntreprise.getRaisonSociale());
|
||||||
|
|
||||||
|
//Première commande
|
||||||
|
System.out.println("Préparons votre commande :"+laCommande1.toString());
|
||||||
|
System.out.println("Voici les instruments en stock :");
|
||||||
|
//ajouter des instruments de l'entreprise à la commande
|
||||||
|
boolean rep=false;
|
||||||
|
do {
|
||||||
|
int ref=menu(lEntreprise); //le menu affiche les instruments
|
||||||
|
System.out.print("En quelle quantité ?");
|
||||||
|
int qte=lectureClavier.nextInt();
|
||||||
|
laCommande1.ajouter(lEntreprise.getLesInstruments().get(ref), qte);
|
||||||
|
System.out.print("Voulez-vous ajouter un autre instrument à votre commande (oui/non) ?");
|
||||||
|
String reponse=lectureClavier.next();
|
||||||
|
rep = "oui".equals(reponse);
|
||||||
|
}while(rep);
|
||||||
|
//affecter la commande à l'entreprise si la commande est possible
|
||||||
|
lEntreprise.ajouterCommande(laCommande1);
|
||||||
|
System.out.println("Voici votre commande"+lEntreprise.getLesCommandes().get(0));
|
||||||
|
|
||||||
|
//--------------------------------------
|
||||||
|
//créer une autre commande
|
||||||
|
System.out.println("Voilà l'autre commande :"+laCommande2.toString());
|
||||||
|
System.out.println("Voici les instruments en stock :");
|
||||||
|
//ajouter des instruments de l'entreprise à la commande
|
||||||
|
rep=false;
|
||||||
|
do {
|
||||||
|
int ref=menu(lEntreprise);
|
||||||
|
System.out.print("En quelle quantité ?");
|
||||||
|
int qte=lectureClavier.nextInt();
|
||||||
|
laCommande2.ajouter(lEntreprise.getLesInstruments().get(ref), qte);
|
||||||
|
System.out.print("Voulez-vous ajouter un autre instrument à votre commande (oui/non) ?");
|
||||||
|
String reponse=lectureClavier.next();
|
||||||
|
rep = "oui".equals(reponse);
|
||||||
|
}while(rep);
|
||||||
|
//affecter la commande à l'entreprise si la commande est possible
|
||||||
|
lEntreprise.ajouterCommande(laCommande2);
|
||||||
|
System.out.println("Voici votre commande"+lEntreprise.getLesCommandes().get(1));
|
||||||
|
|
||||||
|
//rechercher et afficher une commande
|
||||||
|
|
||||||
|
|
||||||
|
//supprimer une des 2 commandes
|
||||||
|
|
||||||
|
//vériffier les stocks après suppression de la commande
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
static int menu(Entreprise uneEnt){
|
||||||
|
Scanner lectureClavier=new Scanner(System.in);
|
||||||
|
System.out.println("Choisir un instrument :");
|
||||||
|
int i=0;
|
||||||
|
for(Instrument lInst : uneEnt.getLesInstruments()){
|
||||||
|
i=i+1;
|
||||||
|
System.out.print(i + "- ");
|
||||||
|
System.out.println(lInst.toString());
|
||||||
|
}
|
||||||
|
System.out.print("Quel instrument voulez-vous ? ");
|
||||||
|
return lectureClavier.nextInt()-1;
|
||||||
|
}
|
||||||
|
}
|
@ -1,28 +0,0 @@
|
|||||||
|
|
||||||
import métiers.Commande;
|
|
||||||
import métiers.Entreprise;
|
|
||||||
import métiers.Instrument;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author sio
|
|
||||||
*/
|
|
||||||
public class Test {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param args the command line arguments
|
|
||||||
*/
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Entreprise lEntreprise=new Entreprise("MusicAndCo");
|
|
||||||
Commande laCommande = new Commande(1,1,"12/09/2024");
|
|
||||||
lEntreprise.ajouterCommande(laCommande);
|
|
||||||
|
|
||||||
//ajouter 3 piano droit et 2 violon alto dans la commande
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -36,18 +36,44 @@ private final HashMap<Instrument, Integer> lesLignes = new HashMap<>();
|
|||||||
* @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;
|
boolean ajoutOK=false;
|
||||||
|
if(qte==0) System.out.println("Vous ne pouvez pas commander une quantité 0");
|
||||||
|
else{
|
||||||
|
//ajout d'un instrument existant dans la commande, ce sera une mise à jour de la ligne
|
||||||
|
if (lesLignes.containsKey(unInstrument))//l'instrument existe
|
||||||
|
{
|
||||||
|
//récupération de la quantité en stock
|
||||||
|
int oldQte=unInstrument.getQteStock();
|
||||||
|
//réaffectation dans le stock de la quantité commandée
|
||||||
|
int qteStock=oldQte+ this.getLesLignes().get(unInstrument);
|
||||||
|
unInstrument.setQteStock(qteStock);
|
||||||
|
//suppression ligne commande
|
||||||
|
lesLignes.remove(unInstrument);
|
||||||
|
//nouvel ajout
|
||||||
|
this.ajouter(unInstrument,qte);
|
||||||
|
System.out.println("Ligne de commande préexistante mise à jour");
|
||||||
|
}
|
||||||
|
else //nouvel instrument
|
||||||
|
{
|
||||||
|
//on s'assure qu'il y a assez de stock pour la commande
|
||||||
|
|
||||||
int qteDisponible = unInstrument.getQteStock();
|
int qteDisponible = unInstrument.getQteStock();
|
||||||
if (qteDisponible<qte){
|
if (qteDisponible<qte){
|
||||||
ajoutOK = false;
|
ajoutOK = false;
|
||||||
|
System.out.println("Ajout impossible, quantité en stock insuffisante");
|
||||||
}else {
|
}else {
|
||||||
ajoutOK = true;
|
ajoutOK = true;
|
||||||
lesLignes.put(unInstrument,qte);
|
lesLignes.put(unInstrument,qte);
|
||||||
|
//màj qté stock pour déduire la qté commandée
|
||||||
unInstrument.setQteStock(qteDisponible-qte);
|
unInstrument.setQteStock(qteDisponible-qte);
|
||||||
|
System.out.println("Instrument ajouté à la commande");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ajoutOK;
|
return ajoutOK;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -60,6 +86,12 @@ private final HashMap<Instrument, Integer> lesLignes = new HashMap<>();
|
|||||||
boolean suppOK;
|
boolean suppOK;
|
||||||
if (lesLignes.containsKey(unInstrument) == true){
|
if (lesLignes.containsKey(unInstrument) == true){
|
||||||
suppOK = true;
|
suppOK = true;
|
||||||
|
//récupération de la quantité en stock
|
||||||
|
int oldQte=unInstrument.getQteStock();
|
||||||
|
//réaffectation dans le stock de la quantité commandée
|
||||||
|
int qteStock=oldQte+ this.getLesLignes().get(unInstrument);
|
||||||
|
unInstrument.setQteStock(qteStock);
|
||||||
|
//suppression ligne commande
|
||||||
lesLignes.remove(unInstrument);
|
lesLignes.remove(unInstrument);
|
||||||
} else {
|
} else {
|
||||||
suppOK = false;
|
suppOK = false;
|
||||||
@ -119,5 +151,10 @@ private final HashMap<Instrument, Integer> lesLignes = new HashMap<>();
|
|||||||
return Objects.equals(this.dateCom, other.dateCom);
|
return Objects.equals(this.dateCom, other.dateCom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return " "+noCom+" du vendeur " + noVendeur + ", du " + dateCom + ", contient " + lesLignes + '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,17 +15,33 @@ 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;
|
||||||
|
|
||||||
ArrayList<Instrument> lesInstruments = new ArrayList<>();
|
|
||||||
Instrument instr1=new Instrument(23,"Piano droit",3, 8300f);
|
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(instr2);
|
|
||||||
lesInstruments.add(instr1);
|
lesInstruments.add(instr1);
|
||||||
|
lesInstruments.add(instr2);
|
||||||
|
lesInstruments.add(instr3);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Commande> getLesCommandes() {
|
||||||
|
return lesCommandes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLesCommandes(ArrayList<Commande> lesCommandes) {
|
||||||
|
this.lesCommandes = lesCommandes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Instrument> getLesInstruments() {
|
||||||
|
return lesInstruments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLesInstruments(ArrayList<Instrument> lesInstruments) {
|
||||||
|
this.lesInstruments = lesInstruments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRaisonSociale() {
|
public String getRaisonSociale() {
|
||||||
|
@ -25,7 +25,7 @@ public class Instrument {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Instrument{" + "ref=" + ref + ", designation=" + designation + ", qteStock=" + qteStock + ", prix=" + prix + '}';
|
return designation + ", Stock=" + qteStock + ", prix=" + prix ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRef(int ref) {
|
public void setRef(int ref) {
|
||||||
|
@ -5,9 +5,7 @@
|
|||||||
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.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -18,19 +16,21 @@ 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,32 +42,79 @@ 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");
|
||||||
/*INES*/
|
laCommande.ajouter(instr2, 0);
|
||||||
|
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.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user