diff --git a/nbproject/project.properties b/nbproject/project.properties index f35ff40..53803b8 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,99 +1,99 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=false -annotation.processing.processor.options= -annotation.processing.processors.list= -annotation.processing.run.all.processors=true -annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output -build.classes.dir=${build.dir}/classes -build.classes.excludes=**/*.java,**/*.form -# This directory is removed when the project is cleaned: -build.dir=build -build.generated.dir=${build.dir}/generated -build.generated.sources.dir=${build.dir}/generated-sources -# Only compile against the classpath explicitly listed here: -build.sysclasspath=ignore -build.test.classes.dir=${build.dir}/test/classes -build.test.results.dir=${build.dir}/test/results -# Uncomment to specify the preferred debugger connection transport: -#debug.transport=dt_socket -debug.classpath=\ - ${run.classpath} -debug.modulepath=\ - ${run.modulepath} -debug.test.classpath=\ - ${run.test.classpath} -debug.test.modulepath=\ - ${run.test.modulepath} -# Files in build.classes.dir which should be excluded from distribution jar -dist.archive.excludes= -# This directory is removed when the project is cleaned: -dist.dir=dist -dist.jar=${dist.dir}/MusicAndCo.jar -dist.javadoc.dir=${dist.dir}/javadoc -dist.jlink.dir=${dist.dir}/jlink -dist.jlink.output=${dist.jlink.dir}/MusicAndCo -excludes= -includes=** -jar.compress=false -javac.classpath= -# Space-separated list of extra javac options -javac.compilerargs=\ --enable-preview --enable-preview -javac.deprecation=false -javac.external.vm=true -javac.modulepath= -javac.processormodulepath= -javac.processorpath=\ - ${javac.classpath} -javac.source=21 -javac.target=21 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir}:\ - ${libs.testng.classpath}:\ - ${libs.junit_5.classpath}:\ - ${libs.junit_4.classpath}:\ - ${libs.hamcrest.classpath} -javac.test.modulepath=\ - ${javac.modulepath} -javac.test.processorpath=\ - ${javac.test.classpath} -javadoc.additionalparam= -javadoc.author=false -javadoc.encoding=${source.encoding} -javadoc.html5=false -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.private=false -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle= -# The jlink additional root modules to resolve -jlink.additionalmodules= -# The jlink additional command line parameters -jlink.additionalparam= -jlink.launcher=true -jlink.launcher.name=MusicAndCo -main.class=Test -manifest.file=manifest.mf -meta.inf.dir=${src.dir}/META-INF -mkdist.disabled=false -platform.active=default_platform -run.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -# Space-separated list of JVM arguments used when running the project. -# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. -# To set system properties for unit tests define test-sys-prop.name=value: -run.jvmargs=\ --enable-preview -run.modulepath=\ - ${javac.modulepath} -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -run.test.modulepath=\ - ${javac.test.modulepath} -source.encoding=UTF-8 -src.dir=src -test.src.dir=test +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/MusicAndCo.jar +dist.javadoc.dir=${dist.dir}/javadoc +dist.jlink.dir=${dist.dir}/jlink +dist.jlink.output=${dist.jlink.dir}/MusicAndCo +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs=\ --enable-preview --enable-preview +javac.deprecation=false +javac.external.vm=true +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=21 +javac.target=21 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.testng.classpath}:\ + ${libs.junit_5.classpath}:\ + ${libs.junit_4.classpath}:\ + ${libs.hamcrest.classpath} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.html5=false +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# The jlink additional root modules to resolve +jlink.additionalmodules= +# The jlink additional command line parameters +jlink.additionalparam= +jlink.launcher=true +jlink.launcher.name=MusicAndCo +main.class=MusicAndCo.Test +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs=\ --enable-preview +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/src/MusicAndCo/Test.java b/src/MusicAndCo/Test.java new file mode 100644 index 0000000..046c262 --- /dev/null +++ b/src/MusicAndCo/Test.java @@ -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; + } +} diff --git a/src/Test.java b/src/Test.java deleted file mode 100644 index e4c5072..0000000 --- a/src/Test.java +++ /dev/null @@ -1,38 +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 laCommande1 = new Commande(1,1,"12/09/2024"); - - //ajouter des instruments de l'entreprise à 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 - } - -} diff --git a/src/métiers/Commande.java b/src/métiers/Commande.java index aa86c01..03fb9cb 100644 --- a/src/métiers/Commande.java +++ b/src/métiers/Commande.java @@ -40,7 +40,8 @@ private final HashMap lesLignes = new HashMap<>(); //il faut empêcher l'ajout d'une ligne avec une quantité à 0 //bien s'assurer que le stock est suffisant boolean ajoutOK=false; - if(qte!=0){ + 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 { @@ -53,7 +54,7 @@ private final HashMap lesLignes = new HashMap<>(); lesLignes.remove(unInstrument); //nouvel ajout this.ajouter(unInstrument,qte); - + System.out.println("Ligne de commande préexistante mise à jour"); } else //nouvel instrument { @@ -62,14 +63,17 @@ private final HashMap lesLignes = new HashMap<>(); int qteDisponible = unInstrument.getQteStock(); if (qteDisponible lesLignes = new HashMap<>(); boolean suppOK; if (lesLignes.containsKey(unInstrument) == 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); } else { suppOK = false; @@ -140,6 +150,11 @@ private final HashMap lesLignes = new HashMap<>(); } return Objects.equals(this.dateCom, other.dateCom); } + + @Override + public String toString() { + return " "+noCom+" du vendeur " + noVendeur + ", du " + dateCom + ", contient " + lesLignes + '}'; + } } diff --git a/src/métiers/Entreprise.java b/src/métiers/Entreprise.java index 235f9d5..01090d5 100644 --- a/src/métiers/Entreprise.java +++ b/src/métiers/Entreprise.java @@ -23,9 +23,25 @@ public class Entreprise { Instrument instr1=new Instrument(23,"Piano droit",3, 8300f); Instrument instr2=new Instrument(54,"Violon Alto",5, 105f); Instrument instr3=new Instrument(67,"Guitare Classique",8, 575f); - lesInstruments.add(instr3); - lesInstruments.add(instr2); lesInstruments.add(instr1); + lesInstruments.add(instr2); + lesInstruments.add(instr3); + } + + public ArrayList getLesCommandes() { + return lesCommandes; + } + + public void setLesCommandes(ArrayList lesCommandes) { + this.lesCommandes = lesCommandes; + } + + public ArrayList getLesInstruments() { + return lesInstruments; + } + + public void setLesInstruments(ArrayList lesInstruments) { + this.lesInstruments = lesInstruments; } public String getRaisonSociale() { diff --git a/src/métiers/Instrument.java b/src/métiers/Instrument.java index f38de2f..41b0332 100644 --- a/src/métiers/Instrument.java +++ b/src/métiers/Instrument.java @@ -25,7 +25,7 @@ public class Instrument { @Override public String toString() { - return "Instrument{" + "ref=" + ref + ", designation=" + designation + ", qteStock=" + qteStock + ", prix=" + prix + '}'; + return designation + ", Stock=" + qteStock + ", prix=" + prix ; } public void setRef(int ref) { diff --git a/test/métiers/CommandeTest.java b/test/métiers/CommandeTest.java index fa10839..329407e 100644 --- a/test/métiers/CommandeTest.java +++ b/test/métiers/CommandeTest.java @@ -85,8 +85,7 @@ public class CommandeTest { qteRes=laCommande.getLesLignes().get(instr3); qteAttendu=0; assertEquals("Test4 quantite", qteAttendu,qteRes); - - + /*MORGANN*/ System.out.println("Cas5 : mise à 0 quantité commandée d'une ligne existante"); laCommande.ajouter(instr2, 0);