From: Jérôme Benoit Date: Sun, 4 Mar 2018 19:27:30 +0000 (+0100) Subject: TP2: Fix the Compactable implementation in Image class. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;ds=inline;h=0f1b20188428cc8f90cb68ec4775f0b67be0c077;hp=39d7332090951dc583cd3039fd6b18b809a88693;p=TP_POO.git TP2: Fix the Compactable implementation in Image class. Signed-off-by: Jérôme Benoit --- diff --git a/TP2/Image.java b/TP2/Image.java index 62a710c..37bc6c3 100644 --- a/TP2/Image.java +++ b/TP2/Image.java @@ -59,13 +59,16 @@ class Image extends Forme implements Compactable { } public void afficher() { + String className = this.getClass().getSimpleName(); + System.out.println("---- " + className + " ----"); for (int i = 0; i < formeNumber; i++) { formeCollection[i].afficher(); } } public void compacter(int nElements) { - for (int i = formeNumber - 1; (i > formeNumber - nElements && !isEmpty()); i--) { + int minIndex = formeNumber - nElements - 1; + for (int i = formeNumber - 1; (i > minIndex && !isEmpty()); i--) { supprimer(i); } } diff --git a/TP2/Main.java b/TP2/Main.java index 85c21fe..05eb447 100644 --- a/TP2/Main.java +++ b/TP2/Main.java @@ -127,7 +127,7 @@ class Main { liste.inserer(4); for (int i = 0; i < 10; i++) { - structure[i] = entier; + structure[i] = entiers; structure[i].afficher(); structure[i].compacter(1); structure[i].afficher(); @@ -136,12 +136,11 @@ class Main { structure[i].afficher(); structure[i].compacter(1); structure[i].afficher(); - - structure[i] = image; - structure[i].afficher(); - structure[i].compacter(1); - structure[i].afficher(); } + + image.afficher(); + image.compacter(1); + image.afficher(); } public static void main(String[] args) {