From c7c510eb1829b97b642bd584a8737103b07efeb7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 16 Feb 2018 10:45:54 +0100 Subject: [PATCH] TP2: Finally make all Affichable implemented classes uniform. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit And add a better test case. Signed-off-by: Jérôme Benoit --- Structure/Liste.java | 2 +- TP2/Cercle.java | 2 ++ TP2/Entiers.java | 5 +++-- TP2/Liste.java | 5 +++-- TP2/Main.java | 36 +++++++++++++++++++++++++++++++++++- TP2/Segment.java | 2 ++ 6 files changed, 46 insertions(+), 6 deletions(-) diff --git a/Structure/Liste.java b/Structure/Liste.java index b31d081..da22d8a 100644 --- a/Structure/Liste.java +++ b/Structure/Liste.java @@ -120,7 +120,7 @@ public class Liste extends Structure { public void afficher() { System.out.println("---- liste ----"); if (isEmpty()) { - System.out.println("Liste vide"); + return; } else if (headNode.getNext() == null) { System.out.println("element 0 : " + headNode.getData()); } else { diff --git a/TP2/Cercle.java b/TP2/Cercle.java index f595ffd..68e6289 100644 --- a/TP2/Cercle.java +++ b/TP2/Cercle.java @@ -15,6 +15,8 @@ class Cercle extends Forme { } public void afficher() { + String className = this.getClass().getSimpleName(); + System.out.println("---- " + className + " ----"); System.out.println(super.getpOri().toString() + " " + rayon); } diff --git a/TP2/Entiers.java b/TP2/Entiers.java index b4cffb1..80fcc90 100644 --- a/TP2/Entiers.java +++ b/TP2/Entiers.java @@ -60,7 +60,7 @@ class Entiers extends Structure { private int binarySearch(int first, int last, int value) { if (last < first) - //FIXME: should not return an integer + //FIXME: should not return an integer return -1; int middle = (first + last) / 2; if (value == int_array[middle]) @@ -98,7 +98,8 @@ class Entiers extends Structure { } public void afficher() { - System.out.println("---- entiers ----"); + String className = this.getClass().getSimpleName(); + System.out.println("---- " + className + " ----"); for (int i = 0; i < getCurrentSize(); i++) { System.out.println("element " + i + " : " + int_array[i]); } diff --git a/TP2/Liste.java b/TP2/Liste.java index b31d081..2a2aff2 100644 --- a/TP2/Liste.java +++ b/TP2/Liste.java @@ -118,9 +118,10 @@ public class Liste extends Structure { } public void afficher() { - System.out.println("---- liste ----"); + String className = this.getClass().getSimpleName(); + System.out.println("---- " + className + " ----"); if (isEmpty()) { - System.out.println("Liste vide"); + return; } else if (headNode.getNext() == null) { System.out.println("element 0 : " + headNode.getData()); } else { diff --git a/TP2/Main.java b/TP2/Main.java index e8a3ca5..49473b4 100644 --- a/TP2/Main.java +++ b/TP2/Main.java @@ -64,9 +64,43 @@ class Main { transformations.depiler(); } + public static void main3() { + + Affichable[] affichable = new Affichable[10]; + + Point p1 = new Point(1, 2); + Point p2 = new Point(2, 7); + Point p3 = new Point(1, 5); + + Entiers entiers = new Entiers(5); + entiers.inserer(3); + entiers.inserer(1); + entiers.inserer(5); + + Liste liste = new Liste(); + liste.inserer(3); + liste.inserer(1); + liste.inserer(5); + + for (int i = 0; i < 10; i++) { + affichable[i] = entiers; + affichable[i].afficher(); + + affichable[i] = liste; + affichable[i].afficher(); + + affichable[i] = new Segment(p1, p2); + affichable[i].afficher(); + + affichable[i] = new Cercle(p3, 5.5); + affichable[i].afficher(); + } + + } + public static void main(String[] args) { - main2(); + main3(); } diff --git a/TP2/Segment.java b/TP2/Segment.java index 48809c5..2ec075c 100644 --- a/TP2/Segment.java +++ b/TP2/Segment.java @@ -27,6 +27,8 @@ class Segment extends Forme { } public void afficher() { + String className = this.getClass().getSimpleName(); + System.out.println("---- " + className + " ----"); System.out.println(super.getpOri().toString() + " " + pDest.toString()); } -- 2.34.1