From 0f1b20188428cc8f90cb68ec4775f0b67be0c077 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 4 Mar 2018 20:27:30 +0100 Subject: [PATCH 1/1] TP2: Fix the Compactable implementation in Image class. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- TP2/Image.java | 5 ++++- TP2/Main.java | 11 +++++------ 2 files changed, 9 insertions(+), 7 deletions(-) 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) { -- 2.34.1