TP2: Finally make all Affichable implemented classes uniform.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 16 Feb 2018 09:45:54 +0000 (10:45 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 16 Feb 2018 09:45:54 +0000 (10:45 +0100)
And add a better test case.

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
Structure/Liste.java
TP2/Cercle.java
TP2/Entiers.java
TP2/Liste.java
TP2/Main.java
TP2/Segment.java

index b31d0816218f2db6028c5edf8ff4ac14a5392852..da22d8afa47ba9d7a5b021009acde7a4c2e9058e 100644 (file)
@@ -120,7 +120,7 @@ public class Liste extends Structure {
     public void afficher() {
         System.out.println("---- liste ----");
         if (isEmpty()) {
     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 {
         } else if (headNode.getNext() == null) {
             System.out.println("element 0 : " + headNode.getData());
         } else {
index f595ffd1a9549c93dafa90d520d4bada0ac0bcfa..68e62891de11e4f2e1566a5130ab9c03c9450364 100644 (file)
@@ -15,6 +15,8 @@ class Cercle extends Forme {
     }
 
     public void afficher() {
     }
 
     public void afficher() {
+        String className = this.getClass().getSimpleName();
+        System.out.println("---- " + className + " ----");
         System.out.println(super.getpOri().toString() + " " + rayon);
     }
 
         System.out.println(super.getpOri().toString() + " " + rayon);
     }
 
index b4cffb15f6f90406be47212e9f9dede7a02f1e66..80fcc9016434b0b5ec16c3f946c1999e37097fa3 100644 (file)
@@ -60,7 +60,7 @@ class Entiers extends Structure {
 
     private int binarySearch(int first, int last, int value) {
         if (last < first)
 
     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])
             return -1;
         int middle = (first + last) / 2;
         if (value == int_array[middle])
@@ -98,7 +98,8 @@ class Entiers extends Structure {
     }
 
     public void afficher() {
     }
 
     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]);
         }
         for (int i = 0; i < getCurrentSize(); i++) {
             System.out.println("element " + i + " : " + int_array[i]);
         }
index b31d0816218f2db6028c5edf8ff4ac14a5392852..2a2aff29af1ab516ede9be36d3512b5ed2cf2b67 100644 (file)
@@ -118,9 +118,10 @@ public class Liste extends Structure {
     }
 
     public void afficher() {
     }
 
     public void afficher() {
-        System.out.println("---- liste ----");
+        String className = this.getClass().getSimpleName();
+        System.out.println("---- " + className + " ----");
         if (isEmpty()) {
         if (isEmpty()) {
-            System.out.println("Liste vide");
+            return;
         } else if (headNode.getNext() == null) {
             System.out.println("element 0 : " + headNode.getData());
         } else {
         } else if (headNode.getNext() == null) {
             System.out.println("element 0 : " + headNode.getData());
         } else {
index e8a3ca51974038318a90820642b0c03014753bf1..49473b41c1c9f983ba073102c9f91a41ce36702e 100644 (file)
@@ -64,9 +64,43 @@ class Main {
         transformations.depiler();
     }
 
         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) {
 
     public static void main(String[] args) {
 
-        main2();
+        main3();
 
     }
 
 
     }
 
index 48809c599f7334d49f2cd04c4a761a5e2f2e54ec..2ec075c659db70f7720fe77fa39b60c62f0ef98f 100644 (file)
@@ -27,6 +27,8 @@ class Segment extends Forme {
     }
 
     public void afficher() {
     }
 
     public void afficher() {
+        String className = this.getClass().getSimpleName();
+        System.out.println("---- " + className + " ----");
         System.out.println(super.getpOri().toString() + " " + pDest.toString());
     }
 
         System.out.println(super.getpOri().toString() + " " + pDest.toString());
     }