diff --git a/APL2.1/TP16/Couleurs/Couleurs.class b/APL2.1/TP16/Couleurs/Couleurs.class index dece8b5..17f10d9 100644 Binary files a/APL2.1/TP16/Couleurs/Couleurs.class and b/APL2.1/TP16/Couleurs/Couleurs.class differ diff --git a/APL2.1/TP16/Couleurs/Couleurs.java b/APL2.1/TP16/Couleurs/Couleurs.java index d1551fb..8768993 100644 --- a/APL2.1/TP16/Couleurs/Couleurs.java +++ b/APL2.1/TP16/Couleurs/Couleurs.java @@ -65,6 +65,12 @@ public class Couleurs extends JPanel { newG.setColor(colorList[index2]); newG.fillPolygon(new int[] {0, this.getWidth(), this.getWidth()}, new int[] {0, 0, this.getHeight()}, 3); + + newG.setColor(colorList[index1]); + newG.drawString(nameList[index2], this.getWidth() - 150, 20); + + newG.setColor(colorList[index2]); + newG.drawString(nameList[index1], 20, this.getHeight() - 20); } } } diff --git a/APL2.1/TP16/Couleurs/Listener.java b/APL2.1/TP16/Couleurs/Listener.java index 662ceaa..320c391 100644 --- a/APL2.1/TP16/Couleurs/Listener.java +++ b/APL2.1/TP16/Couleurs/Listener.java @@ -1,3 +1,3 @@ -public class Listener extends MouseListener { +/*public class Listener extends MouseListener { -} +}*/ diff --git a/DEV 2.3/Sorting/Sorting.class b/DEV 2.3/Sorting/Sorting.class new file mode 100644 index 0000000..3ca8c76 Binary files /dev/null and b/DEV 2.3/Sorting/Sorting.class differ diff --git a/DEV 2.3/Sorting/Sorting.java b/DEV 2.3/Sorting/Sorting.java new file mode 100644 index 0000000..8f8c1f1 --- /dev/null +++ b/DEV 2.3/Sorting/Sorting.java @@ -0,0 +1,35 @@ +import java.util.Objects; + +/** + * Sorting + */ +public class Sorting { + + public static void main(String[] args) { + + } + + /** + * Prend en entrée un tableau de double et renvoie le même tableau avec ses données triées. + * @param table Le tableau de doubles + * @throws NullPointerException Le tableau donné est nul + * @return Le même tableau trié + */ + public static double[] sort(double[] table) { + Objects.requireNonNull(table); + if (table.length < 2) return table; + + double[] sortedArray = new double[table.length]; + for (int i = 1; i < table.length-1; i++) { + double x = table[i]; + int j = i; + while (j > 0 && table[j-1] > x) { + sortedArray[j] = table[j - 1]; + j--; + } + + sortedArray[j] = x; + } + return sortedArray; + } +} \ No newline at end of file diff --git a/DEV 2.3/Sorting/Tests.class b/DEV 2.3/Sorting/Tests.class new file mode 100644 index 0000000..0209c0b Binary files /dev/null and b/DEV 2.3/Sorting/Tests.class differ diff --git a/DEV 2.3/Sorting/Tests.java b/DEV 2.3/Sorting/Tests.java new file mode 100644 index 0000000..9a5d117 --- /dev/null +++ b/DEV 2.3/Sorting/Tests.java @@ -0,0 +1,45 @@ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import java.util.Arrays; + +public class Tests { + + @Test + public void testOrdered() { + double[] arr = Sorting.sort(new double[] {5.225, 2592.2 ,218.1, 2952895828528.1, 11.2, -25.1}); + + for (int i = 1; i < arr.length; i++) { + assertTrue(arr[i] >= arr[i-1]); + } + } + + @Test + public void testSorted() { + double[] arr = new double[] {3.2, 589.2, 28582.1, 4.285824, 6.5282}; + double[] sortedArr = new double[] {3.2, 4.285824, 6.5282, 589.2, 28582.1}; + + System.out.println(Arrays.toString(sortedArr)); + System.out.println(Arrays.toString(Sorting.sort(arr))); + assertTrue(Arrays.equals(sortedArr, Sorting.sort(arr))); + + } + + @Test + public void testZeroOneElementTable() { + Sorting.sort(new double[] {}); + Sorting.sort(new double[] {1}); + } + + @Test + public void testAlreadySorted() { + double[] arr = new double[] {1.5, 2.7, 3.82, 5.5, 189.22}; + assertTrue(Arrays.equals(arr, Sorting.sort(arr))); + } + + @Test(expected = NullPointerException.class) + public void testNullTable() { + Sorting.sort(null); + } +}