diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..a55e7a1
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..c64cd18
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..aa00ffa
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..712ab9d
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..67e1e61
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 481648b..359dbe1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,20 +1,24 @@
- 4.0.0
- diginamic
- codePropre
- 0.0.1-SNAPSHOT
-
- src/main/java
-
-
- maven-compiler-plugin
- 3.5.1
-
- 1.8
- 1.8
-
-
-
-
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ 4.0.0
+ diginamic
+ codePropre
+ 0.0.1-SNAPSHOT
+
+ UTF-8
+
+
+
+ src/main/java
+
+
+ maven-compiler-plugin
+ 3.5.1
+
+ 1.8
+ 1.8
+
+
+
+
\ No newline at end of file
diff --git a/src/README.md b/src/README.md
new file mode 100644
index 0000000..9a361c5
--- /dev/null
+++ b/src/README.md
@@ -0,0 +1,54 @@
+# code-propre
+## Nettoyage de code
+
+### Exercice 2
+
+Le livret A n’était pas documenté.
+
+Le compte courant ne semble pas exister.
+Le compte bancaire devrait être une classe abstraite dont héritent le compte
+courant et le livret A.
+
+Si le livret A est le seul à avoir un taux de rémunération annuel le compte
+bancaire n’est pas sensé en avoir.
+
+Appeler la classe mère `Object` par le constructeur `super` est inutile dans
+la classe `CompteBancaire`: il est implicite.
+
+La méthode `debiterMontant` ne sera vraiment appliquée que dans les classes
+filles.
+~~Autant qu’elle soit abstraite dans `CompteBancaire` et définies dans chaque
+classe fille.~~ Elle peut être simplifiée puisque l’absence de découvert
+peut être illustrée par `decouvert=0`.
+De plus sa documentation est incorrecte.
+
+La méthode `appliquerRemunerationAnnuelle` est mal nommée et devrait être
+définie dans la classe `LivretA`.
+
+Le solde `solde` n’a pas besoin de mutateur `setSolde`.
+Les méthodes `ajouterMontant` et `debiterMontant` gèrent son évolution avec
+plus de contrôle.
+
+Autre détail : tabulation convertie en 4 espaces pour indenter.
+
+### Exercice 3
+
+« Je comprends que tu as un parc zoologique où tu accueilles toute sorte
+d’animaux.
+Du coup, je me serais attendu à croiser au moins une classe `Animal` en plus de
+la classe `Zoo`.
+Plus encore, j’aurais fait des sous-classes suivant l’arbre phylogénique des
+bêtes citées dans la classe exécutable `ZooApplication`.
+
+Après si ces bêtes ne sont qu’une source de donnée, on peut juste les
+rassembler sous forme d’un dictionnaire `HashMap` selon les
+attributs `types`, `noms` et `comportements`.
+La raison est que ça permet de mettre en avant la corrélation des attributs,
+mais aussi de distinguer chaque bête partageant les mêmes attributs.
+La ligne `0` peut être réservée comme en-tête d’un tableau futur.
+
+Après, je ne connais pas l’application exacte.
+
+Je fais juste une petite correction en assignant tes attributs à des objets
+`ArrayList` vides et en renommant `types` en `typeAnimal`…
+Voilà, la méthode `afficherListeAnimaux` remarche. »
\ No newline at end of file
diff --git a/src/main/java/ex1/Entreprise.java b/src/main/java/ex1/Entreprise.java
new file mode 100644
index 0000000..df62f54
--- /dev/null
+++ b/src/main/java/ex1/Entreprise.java
@@ -0,0 +1,21 @@
+package ex1;
+
+import java.util.Date;
+/** Entreprise */
+public class Entreprise {
+ /** Numéro de siret */
+ public int siret;
+ /** Nom */
+ public String nom;
+ /** Adresse */
+ public String adresse;
+ /** Date de création */
+ public Date dateCreation;
+ /** Capital maximal */
+ public static final int capitalMax = 3000000;
+
+ /**
+ * Afficher le status
+ */
+ public void afficherStatut(){}
+}
diff --git a/src/main/java/ex1/calcul.java b/src/main/java/ex1/calcul.java
index f0d9cd8..4d0423b 100644
--- a/src/main/java/ex1/calcul.java
+++ b/src/main/java/ex1/calcul.java
@@ -1,12 +1,12 @@
package ex1;
-
+/** Calcul */
public class calcul {
-
- public int get1(int a, int b){
- return a+b;
- }
-
- public int get2(int a, int b){
- return a-b;
- }
+ /** Addition */
+ public int addition(int a, int b){
+ return a+b;
+ }
+ /** Soustraction */
+ public int soustraction(int a, int b){
+ return a-b;
+ }
}
diff --git a/src/main/java/ex1/entreprise.java b/src/main/java/ex1/entreprise.java
deleted file mode 100644
index 32d27bf..0000000
--- a/src/main/java/ex1/entreprise.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package ex1;
-
-import java.util.Date;
-
-public class entreprise {
-
- public int Siret;
- public String Nom;
- public String adresse;
- public Date date_Creation;
-
- public static final int capitalMax = 3000000;
-
- public void Afficher_statut(){
-
- }
-
-}
diff --git a/src/main/java/ex2/CompteBancaire.java b/src/main/java/ex2/CompteBancaire.java
index f7e68b3..7caea80 100644
--- a/src/main/java/ex2/CompteBancaire.java
+++ b/src/main/java/ex2/CompteBancaire.java
@@ -1,125 +1,84 @@
package ex2;
-/** Représente un compte bancaire de type compte courante (type=CC) ou livret A (type=LA)
+/** Représente un compte bancaire de type compte courant (type=CC)
+ * ou livret A (type=LA)
* @author DIGINAMIC
+ * @author FYHenry
*/
-public class CompteBancaire {
+abstract class CompteBancaire {
- /** solde : solde du compte */
- private double solde;
-
- /** decouvert : un découvert est autorisé seulement pour les comptes courants */
- private double decouvert;
-
- /** tauxRemuneration : taux de rémunération dans le cas d'un livret A */
- private double tauxRemuneration;
-
- /** Le type vaut soit CC=Compte courant, ou soit LA=Livret A */
- private String type;
-
- /**
- * @param solde
- * @param decouvert
- * @param type
- */
- public CompteBancaire(String type, double solde, double decouvert) {
- super();
- this.type = type;
- this.solde = solde;
- this.decouvert = decouvert;
- }
-
-
- /** Ce constructeur est utilisé pour créer un compte de type Livret A
- * @param type = LA
- * @param solde représente le solde du compte
- * @param decouvert représente le découvert autorisé
- * @param tauxRemuneration représente le taux de rémunération du livret A
- */
- public CompteBancaire(String type, double solde, double decouvert, double tauxRemuneration) {
- super();
- this.type = type;
- this.solde = solde;
- this.decouvert = decouvert;
- this.tauxRemuneration = tauxRemuneration;
- }
-
- /** Ajoute un montant au solde
- * @param montant
- */
- public void ajouterMontant(double montant){
- this.solde += montant;
- }
-
- /** Ajoute un montant au solde
- * @param montant
- */
- public void debiterMontant(double montant){
- if (type.equals("CC")){
- if (this.solde - montant > decouvert){
- this.solde = solde - montant;
- }
- }
- else if (type.equals("LA")){
- if (this.solde - montant > 0){
- this.solde = solde - montant;
- }
- }
- }
-
- public void appliquerRemuAnnuelle(){
- if (type.equals("LA")){
- this.solde = solde + solde*tauxRemuneration/100;
- }
- }
-
- /** Getter for solde
- * @return the solde
- */
- public double getSolde() {
- return solde;
- }
-
- /** Setter
- * @param solde the solde to set
- */
- public void setSolde(double solde) {
- this.solde = solde;
- }
- /** Getter for decouvert
- * @return the decouvert
- */
- public double getDecouvert() {
- return decouvert;
- }
- /** Setter
- * @param decouvert the decouvert to set
- */
- public void setDecouvert(double decouvert) {
- this.decouvert = decouvert;
- }
- /** Getter for tauxRemuneration
- * @return the tauxRemuneration
- */
- public double getTauxRemuneration() {
- return tauxRemuneration;
- }
- /** Setter
- * @param tauxRemuneration the tauxRemuneration to set
- */
- public void setTauxRemuneration(double tauxRemuneration) {
- this.tauxRemuneration = tauxRemuneration;
- }
- /** Getter for type
- * @return the type
- */
- public String getType() {
- return type;
- }
- /** Setter
- * @param type the type to set
- */
- public void setType(String type) {
- this.type = type;
- }
+ /** solde : solde du compte */
+ protected double solde;
+
+ /** decouvert : un découvert est autorisé seulement pour les
+ * comptes courants.
+ */
+ protected double decouvert;
+
+ /** Le type vaut soit "CC" (Compte courant), soit "LA" (Livret A) */
+ private final String type;
+
+
+ /**
+ * Construction du compte courant selon son solde et
+ * son découvert maximal autorisé.
+ * @param solde Solde
+ * @param decouvert Découvert
+ * @param type Type
+ */
+ public CompteBancaire(String type, double solde, double decouvert) {
+ super();
+ this.type = type;
+ this.solde = solde;
+ this.decouvert = decouvert;
+ }
+
+ /** Ajoute un montant au solde
+ * @param montant Montant
+ */
+ public void ajouterMontant(double montant){
+ this.solde += montant;
+ }
+
+ /** Débite un montant au solde
+ * @param montant
+ */
+ public void debiterMontant(double montant) {
+ if (this.solde - montant > this.decouvert){
+ this.solde = this.solde - montant;
+ }
+ }
+
+ /**
+ * Obtenir le solde.
+ * @return Solde
+ */
+ public double getSolde() {
+ return solde;
+ }
+
+ /**
+ * Obtenir le découvert maximal autorisé.
+ * @return Découvert
+ */
+ public double getdecouvert() {
+ return decouvert;
+ }
+
+ /**
+ * Obtenir le type du compte bancaire : "CC" pour le compte
+ * courant ou "LA" pour le livret A.
+ * @return Type de compte
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * Redéfinir le découvert maximal autorisé.
+ * @param decouvert Découvert
+ */
+ public void setDecouvert(double decouvert) {
+ this.decouvert = decouvert;
+ }
}
diff --git a/src/main/java/ex2/CompteBancaireRate.java b/src/main/java/ex2/CompteBancaireRate.java
new file mode 100644
index 0000000..831ff2d
--- /dev/null
+++ b/src/main/java/ex2/CompteBancaireRate.java
@@ -0,0 +1,125 @@
+package ex2;
+
+/** Représente un compte bancaire de type compte courant (type=CC) ou livret A (type=LA)
+ * @author DIGINAMIC
+ */
+public class CompteBancaireRate {
+
+ /** solde : solde du compte */
+ private double solde;
+
+ /** decouvert : un découvert est autorisé seulement pour les comptes courants */
+ private double decouvert;
+
+ /** tauxRemuneration : taux de rémunération dans le cas d'un livret A */
+ private double tauxRemuneration;
+
+ /** Le type vaut soit CC=Compte courant, ou soit LA=Livret A */
+ private String type;
+
+ /**
+ * @param solde
+ * @param decouvert
+ * @param type
+ */
+ public CompteBancaireRate(String type, double solde, double decouvert) {
+ super();
+ this.type = type;
+ this.solde = solde;
+ this.decouvert = decouvert;
+ }
+
+
+ /** Ce constructeur est utilisé pour créer un compte de type Livret A
+ * @param type = LA
+ * @param solde représente le solde du compte
+ * @param decouvert représente le découvert autorisé
+ * @param tauxRemuneration représente le taux de rémunération du livret A
+ */
+ public CompteBancaireRate(String type, double solde, double decouvert, double tauxRemuneration) {
+ super();
+ this.type = type;
+ this.solde = solde;
+ this.decouvert = decouvert;
+ this.tauxRemuneration = tauxRemuneration;
+ }
+
+ /** Ajoute un montant au solde
+ * @param montant
+ */
+ public void ajouterMontant(double montant){
+ this.solde += montant;
+ }
+
+ /** Ajoute un montant au solde
+ * @param montant
+ */
+ public void debiterMontant(double montant){
+ if (type.equals("CC")){
+ if (this.solde - montant > decouvert){
+ this.solde = solde - montant;
+ }
+ }
+ else if (type.equals("LA")){
+ if (this.solde - montant > 0){
+ this.solde = solde - montant;
+ }
+ }
+ }
+
+ public void appliquerRemuAnnuelle(){
+ if (type.equals("LA")){
+ this.solde = solde + solde*tauxRemuneration/100;
+ }
+ }
+
+ /** Getter for solde
+ * @return the solde
+ */
+ public double getSolde() {
+ return solde;
+ }
+
+ /** Setter
+ * @param solde the solde to set
+ */
+ public void setSolde(double solde) {
+ this.solde = solde;
+ }
+ /** Getter for decouvert
+ * @return the decouvert
+ */
+ public double getDecouvert() {
+ return decouvert;
+ }
+ /** Setter
+ * @param decouvert the decouvert to set
+ */
+ public void setDecouvert(double decouvert) {
+ this.decouvert = decouvert;
+ }
+ /** Getter for tauxRemuneration
+ * @return the tauxRemuneration
+ */
+ public double getTauxRemuneration() {
+ return tauxRemuneration;
+ }
+ /** Setter
+ * @param tauxRemuneration the tauxRemuneration to set
+ */
+ public void setTauxRemuneration(double tauxRemuneration) {
+ this.tauxRemuneration = tauxRemuneration;
+ }
+ /** Getter for type
+ * @return the type
+ */
+ public String getType() {
+ return type;
+ }
+ /** Setter
+ * @param type the type to set
+ */
+ public void setType(String type) {
+ this.type = type;
+ }
+}
diff --git a/src/main/java/ex2/CompteCourant.java b/src/main/java/ex2/CompteCourant.java
new file mode 100644
index 0000000..3b2b2fb
--- /dev/null
+++ b/src/main/java/ex2/CompteCourant.java
@@ -0,0 +1,14 @@
+package ex2;
+
+/** Compte courant */
+public class CompteCourant extends CompteBancaire{
+ /**
+ * Construction du compte courant selon son solde et
+ * son découvert maximal autorisé.
+ * @param solde Solde
+ * @param decouvert Découvert
+ */
+ public CompteCourant(double solde, double decouvert) {
+ super("CC", solde, decouvert);
+ }
+}
diff --git a/src/main/java/ex2/LivreA.java b/src/main/java/ex2/LivreA.java
new file mode 100644
index 0000000..40ce0c9
--- /dev/null
+++ b/src/main/java/ex2/LivreA.java
@@ -0,0 +1,31 @@
+package ex2;
+
+public class LivreA extends CompteBancaire{
+
+ /** tauxRemuneration : taux de rémunération dans le cas d'un livret A */
+ private double tauxRemuneration;
+
+ /**
+ * Construction du livret A selon son solde et
+ * son découvert maximal autorisé.
+ * @param solde
+ */
+ public LivreA(double solde) {
+ super("LA", solde, 0);
+ }
+
+ /**
+ * Appliquer le calcul de la rémunération annuelle.
+ */
+ public void appliquerRemunerationAnnuelle(){
+ this.solde = this.solde * (1 + this.tauxRemuneration / 100);
+ }
+
+ public double getTauxRemuneration() {
+ return tauxRemuneration;
+ }
+
+ public void setTauxRemuneration(double tauxRemuneration) {
+ this.tauxRemuneration = tauxRemuneration;
+ }
+}
diff --git a/src/main/java/ex2/LivretA.java b/src/main/java/ex2/LivretA.java
deleted file mode 100644
index 25b00db..0000000
--- a/src/main/java/ex2/LivretA.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package ex2;
-
-public class LivretA extends CompteBancaire {
-
- public LivretA(String type, double solde, double tauxRemuneration) {
- super(type, solde, 0, tauxRemuneration);
- }
-
-}
diff --git a/src/main/java/ex2/LivretARate.java b/src/main/java/ex2/LivretARate.java
new file mode 100644
index 0000000..e2e8237
--- /dev/null
+++ b/src/main/java/ex2/LivretARate.java
@@ -0,0 +1,14 @@
+package ex2;
+/** Représente un compte bancaire de type livret A (type=LA)
+ * @author DIGINAMIC
+ */
+public class LivretARate extends CompteBancaireRate {
+ public LivretARate(String type,
+ double solde,
+ double tauxRemuneration) {
+ super(type,
+ solde,
+ 0,
+ tauxRemuneration);
+ }
+}
diff --git a/src/main/java/ex3/Zoo.java b/src/main/java/ex3/Zoo.java
index fe6f1f0..b02508f 100644
--- a/src/main/java/ex3/Zoo.java
+++ b/src/main/java/ex3/Zoo.java
@@ -1,45 +1,46 @@
package ex3;
+import java.util.ArrayList;
import java.util.List;
public class Zoo {
- private String nom;
- private List types;
- private List noms;
- private List comportements;
-
- public Zoo(String nom){
- this.nom = nom;
- }
-
- public void addAnimal(String nomAnimal, String typeAnimal, String comportement){
- types.add(typeAnimal);
- noms.add(nomAnimal);
- comportements.add(comportement);
- }
-
- public void afficherListeAnimaux(){
- for (int i=0; i typeAnimal = new ArrayList<>();
+ private List noms = new ArrayList<>();
+ private List comportements = new ArrayList<>();
+
+ public Zoo(String nom){
+ this.nom = nom;
+ }
+
+ public void addAnimal(String nomAnimal, String typeAnimal, String comportement){
+ this.typeAnimal.add(typeAnimal);
+ this.noms.add(nomAnimal);
+ this.comportements.add(comportement);
+ }
+
+ public void afficherListeAnimaux(){
+ for (int i=0; i items;
+ /** Poids minimal accepté d’article */
+ private final int POIDS_MIN;
+ /** Poids maximal accepté d’article */
+ private final int POIDS_MAX;
+
+ /**
+ * Construction de la caisse.
+ * @param nom Nom de la caisse
+ * @param poidsMin Poids minimal accepté d’article
+ * @param poidsMax Poids maximal accepté d’article
+ */
+ public Caisse(String nom, int poidsMin, int poidsMax) {
+ super();
+ this.nom = nom;
+ this.items = new ArrayList<>();
+ this.POIDS_MIN = poidsMin;
+ this.POIDS_MAX = poidsMax;
+ }
+
+ /** Getter pour l'attribut nom
+ * @return the nom
+ */
+ public String getNom() {
+ return nom;
+ }
+
+ /** Setter pour l'attribut nom
+ * @param nom the nom to set
+ */
+ public void setNom(String nom) {
+ this.nom = nom;
+ }
+
+ /** Getter pour l'attribut items
+ * @return the items
+ */
+ public List- getItems() {
+ return items;
+ }
+
+ /** Setter pour l'attribut items
+ * @param items the items to set
+ */
+ public void setItems(List
- items) {
+ this.items = items;
+ }
+
+ /**
+ * Ajouter un article.
+ * @param item Article
+ */
+ public void add(Item item){
+ if(item.getPoids() >= POIDS_MIN &&
+ item.getPoids() < POIDS_MAX){
+ this.items.add(item);
+ }
+ }
- private String nom;
- private List
- items;
-
- /** Constructeur
- * @param nom
- */
- public Caisse(String nom) {
- super();
- this.nom = nom;
- this.items = new ArrayList<>();
- }
-
- /** Getter pour l'attribut nom
- * @return the nom
- */
- public String getNom() {
- return nom;
- }
-
- /** Setter pour l'attribut nom
- * @param nom the nom to set
- */
- public void setNom(String nom) {
- this.nom = nom;
- }
-
- /** Getter pour l'attribut items
- * @return the items
- */
- public List
- getItems() {
- return items;
- }
-
- /** Setter pour l'attribut items
- * @param items the items to set
- */
- public void setItems(List
- items) {
- this.items = items;
- }
-
+ /**
+ * Total d’articles encaissés.
+ * @return Total d’articles
+ */
+ public int total(){
+ return this.items.size();
+ }
}
diff --git a/src/main/java/ex5/Ex5Test.java b/src/main/java/ex5/Ex5Test.java
new file mode 100644
index 0000000..ed9e039
--- /dev/null
+++ b/src/main/java/ex5/Ex5Test.java
@@ -0,0 +1,12 @@
+package ex5;
+
+public class Ex5Test {
+ public static void main(String[] args){
+ final Inventaire inventaire = new Inventaire();
+ inventaire.addItem(new Item("Article0", 7));
+ inventaire.addItem(new Item("Article1", 15));
+ inventaire.addItem(new Item("Article2", 1));
+ System.out.println("Taille de l’inventaire: " +
+ inventaire.taille());
+ }
+}
diff --git a/src/main/java/ex5/Inventaire.java b/src/main/java/ex5/Inventaire.java
index 6f95c35..3c1b716 100644
--- a/src/main/java/ex5/Inventaire.java
+++ b/src/main/java/ex5/Inventaire.java
@@ -2,35 +2,48 @@
import java.util.ArrayList;
import java.util.List;
-
+/** Inventaire d’encaissement */
public class Inventaire {
+ /** Ensemble de caisses exploitées */
+ private final List caisses;
+
+ /**
+ * Construction de l’inventaire.
+ */
+ public Inventaire() {
+ this.caisses = new ArrayList<>(3);
+ final String[] noms = {"Petits", "Moyens", "Grands"};
+ final int[] extrema = {Integer.MIN_VALUE, 5, 20, Integer.MAX_VALUE};
+ for(int i=0; i<3; i++){
+ this.caisses.add(new Caisse(noms[i] + " objets",
+ extrema[i],
+ extrema[i+1]));
+ }
+ }
- private List caisses;
+ /**
+ * Ajouter un article.
+ * @param item Article
+ */
+ public void addItem(Item item) {
- public Inventaire() {
- caisses = new ArrayList<>();
- caisses.add(new Caisse("Petits objets"));
- caisses.add(new Caisse("Moyens objets"));
- caisses.add(new Caisse("Grands objets"));
- }
+ //TODO Faites évoluer ce code (idée: c'est la caisse qui doit
+ // "savoir" si elle peut accepter un objet ou non)
+ caisses.forEach(caisse -> caisse.add(item));
+ }
- public void addItem(Item item) {
+ /**
+ * Taille de l’inventaire en articles.
+ * @return Total d’articles
+ */
+ public int taille() {
- //TODO Faites évoluer ce code (idée: c'est le caisse qui doit "savoir" si elle peut accepter un objet ou non)
- if (item.getPoids() < 5) {
- caisses.get(0).getItems().add(item);
- }
- if (item.getPoids() >= 5 && item.getPoids() <= 20) {
- caisses.get(1).getItems().add(item);
- }
- if (item.getPoids() >= 20) {
- caisses.get(2).getItems().add(item);
- }
- }
+ //TODO faites évoluer ce code.
+ int total = 0;
+ for(Caisse caisse: this.caisses){
+ total += caisse.total();
+ }
+ return total;
- public int taille() {
-
- //TODO faites évoluer ce code.
- return caisses.get(0).getItems().size() + caisses.get(1).getItems().size() + caisses.get(2).getItems().size();
- }
+ }
}
diff --git a/src/main/java/ex5/Item.java b/src/main/java/ex5/Item.java
index 4db0bca..1bb7c4a 100644
--- a/src/main/java/ex5/Item.java
+++ b/src/main/java/ex5/Item.java
@@ -1,32 +1,43 @@
package ex5;
-
+/** Article */
public class Item {
+ /** Nom de l’article */
+ private String nom;
+ /** Poids de l’article */
+ private int poids;
+
+ /**
+ * Construction d’un article par son nom et son poids.
+ * @param nom Nom
+ * @param poids Poids
+ */
+ public Item(String nom, int poids) {
+ this.nom = nom;
+ this.poids = poids;
+ }
- private String nom;
- private int poids;
-
- /** Getter pour l'attribut nom
- * @return the nom
- */
- public String getNom() {
- return nom;
- }
- /** Setter pour l'attribut nom
- * @param nom the nom to set
- */
- public void setNom(String nom) {
- this.nom = nom;
- }
- /** Getter pour l'attribut poids
- * @return the poids
- */
- public int getPoids() {
- return poids;
- }
- /** Setter pour l'attribut poids
- * @param poids the poids to set
- */
- public void setPoids(int poids) {
- this.poids = poids;
- }
+ /** Getter pour l'attribut nom
+ * @return the nom
+ */
+ public String getNom() {
+ return nom;
+ }
+ /** Setter pour l'attribut nom
+ * @param nom the nom to set
+ */
+ public void setNom(String nom) {
+ this.nom = nom;
+ }
+ /** Getter pour l'attribut poids
+ * @return the poids
+ */
+ public int getPoids() {
+ return poids;
+ }
+ /** Setter pour l'attribut poids
+ * @param poids the poids to set
+ */
+ public void setPoids(int poids) {
+ this.poids = poids;
+ }
}