commit ddb6015ac03d401062ef631e5b664b81060be920 Author: Laureηt Date: Fri Dec 3 15:57:00 2021 +0100 fin de séance diff --git a/Analyseur.java b/Analyseur.java new file mode 100644 index 0000000..8bbe76f --- /dev/null +++ b/Analyseur.java @@ -0,0 +1,56 @@ +import java.io.*; +import java.util.*; + +/** Analyser des données d'un fichier, une donnée par ligne avec 4 informations + * séparées par des blancs : x, y, ordre (ignorée), valeur. + */ +public class Analyseur { + /** Conserve la somme des valeurs associées à une position. */ + private Map cumuls; + + /** Construire un analyseur vide. */ + public Analyseur() { + cumuls = new HashMap<>(); + } + + /** Charger l'analyseur avec les données du fichier "donnees.java". */ + public void charger() { + try (BufferedReader in = new BufferedReader(new FileReader("donnees.txt"))) { + String ligne = null; + while ((ligne = in.readLine()) != null) { + String[] mots = ligne.split("\\s+"); + assert mots.length == 4; // 4 mots sur chaque ligne + int x = Integer.parseInt(mots[0]); + int y = Integer.parseInt(mots[1]); + Position p = new Position(x, y); + double valeur = Double.parseDouble(mots[3]); + cumuls.put(p, valeur(p) + valeur); + // p.setY(p.getY() + 1); // p.y += 1; + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + /** Obtenir la valeur associée à une position. */ + public double valeur(Position position) { + Double valeur = cumuls.get(position); + return valeur == null ? 0.0 : valeur; + } + + /** Obtenir toutes les données. */ + public Map donnees() { + return Collections.unmodifiableMap(this.cumuls); + } + + /** Affichier les données. */ + public static void main(String[] args) { + Analyseur a = new Analyseur(); + a.charger(); + System.out.println(a.donnees()); + System.out.println("Nombres de positions : " + a.donnees().size()); + + Position p1 = new Position(1,1); + Position p2 = new Position(2,1); + } +} diff --git a/ExempleDeprecated.java b/ExempleDeprecated.java new file mode 100644 index 0000000..f1778b9 --- /dev/null +++ b/ExempleDeprecated.java @@ -0,0 +1,31 @@ +@Deprecated +class A { } + +class B { + @Deprecated + public void m() { + System.out.println("B.m();"); + } +} + +public class ExempleDeprecated { + void m1() { + A a = new A(); + B b = new B(); + b.m(); + } + + //@SuppressWarnings("deprecation") + void m2() { + A a = new A(); + B b = new B(); + b.m(); + } + + public static void main(String[] args) { + ExempleDeprecated ED = new ExempleDeprecated(); + ED.m1(); + ED.m2(); + } + +} diff --git a/ExempleDeprecated.javac b/ExempleDeprecated.javac new file mode 100644 index 0000000..886b696 --- /dev/null +++ b/ExempleDeprecated.javac @@ -0,0 +1,10 @@ +ExempleDeprecated.java:12: warning: [deprecation] A in unnamed package has been deprecated + A a = new A(); + ^ +ExempleDeprecated.java:12: warning: [deprecation] A in unnamed package has been deprecated + A a = new A(); + ^ +ExempleDeprecated.java:14: warning: [deprecation] m() in B has been deprecated + b.m(); + ^ +3 warnings diff --git a/ExempleOverride.java b/ExempleOverride.java new file mode 100644 index 0000000..e85cadf --- /dev/null +++ b/ExempleOverride.java @@ -0,0 +1,36 @@ +class A { + public String unNomTresTresLong(int n) { + return "A" + n; +} } + +class B extends A { + @Override + public String unNomTresTresLong(int n) { + return "B" + n; +} } + +class C extends A { + @Override + public String unNonTresTresLong(int n) { + return "C" + n; +} } + +class D extends A { + @Override + public String unNomTresTresLong(long n) { + return "D" + n; +} } + +public class ExempleOverride { + static void verifier(String attendu, int i, A a) { + String calcul = a.unNomTresTresLong(i); + if (! calcul.equals(attendu)) { + System.out.println("Erreur: " + calcul + " au lieu de " + attendu); + } } + + public static void main(String[] args) { + verifier("A0", 0, new A()); + verifier("B1", 1, new B()); + verifier("C2", 2, new C()); + verifier("D3", 3, new D()); +} } diff --git a/ExempleOverride.javac b/ExempleOverride.javac new file mode 100644 index 0000000..e33e7df --- /dev/null +++ b/ExempleOverride.javac @@ -0,0 +1,7 @@ +ExempleOverride.java:13: error: method does not override or implement a method from a supertype + @Override + ^ +ExempleOverride.java:19: error: method does not override or implement a method from a supertype + @Override + ^ +2 errors diff --git a/Position.java b/Position.java new file mode 100644 index 0000000..73b562b --- /dev/null +++ b/Position.java @@ -0,0 +1,47 @@ +import lombok.*; + +/** Définir une position. */ +@Data @Value +public class Position { + public int x; + public int y; + + // public Position(int x, int y) { + // this.x = x; + // this.y = y; + // // <(NO_TRACE)>// <(/NO_TRACE)>System.out.println("...appel à Position(" + x + "," + y + ")" + " --> " + this); + // System.out.println("...appel à Position(" + x + "," + y + ")" + " --> " + this); + // } + + @Override + public String toString() { + return super.toString() + "(" + x + "," + y + ")"; + } + + @Override + public boolean equals(Object obj) { + Position other = (Position) obj; + return other.x == this.x && other.y == this.y; + } + + @Override + public int hashCode() { + // bijection de Z dans N + int n, m; + if (this.x >= 0) { + n = 2 * this.x; + } else { + n = -2 * this.x - 1; + } + if (this.y >= 0) { + m = 2 * this.y; + } else { + m = -2 * this.y - 1; + } + + // bijection de N² dans N + int h = (n+m)*(n+m+1)/2+m; + return h; + } + +} diff --git a/StringBufferTest.java b/StringBufferTest.java new file mode 100644 index 0000000..2af8294 --- /dev/null +++ b/StringBufferTest.java @@ -0,0 +1,29 @@ +import org.junit.*; +import static org.junit.Assert.*; + +public class StringBufferTest { + private StringBuffer s1; + + @Before public void initialiser() { + s1 = new StringBuffer("Le texte"); + } + + @Test public void testReverse() { + s1.reverse(); + assertEquals("etxet eL", s1.toString()); + } + + @Test public void testDelete() { + s1.delete(2, 7); + assertEquals("Lee", s1.toString()); + } + + @Test(expected=IndexOutOfBoundsException.class) + public void erreurSurIndice() { + assertEquals('e', s1.charAt(-1)); + } + + @Test public void initiale() { + assertEquals('L', s1.charAt(1)); + } +} diff --git a/TP03-packages.jar b/TP03-packages.jar new file mode 100644 index 0000000..8beb961 Binary files /dev/null and b/TP03-packages.jar differ diff --git a/TP03.jar b/TP03.jar new file mode 100644 index 0000000..1da2110 Binary files /dev/null and b/TP03.jar differ diff --git a/donnees.txt b/donnees.txt new file mode 100644 index 0000000..4ae7299 --- /dev/null +++ b/donnees.txt @@ -0,0 +1,11 @@ +1 1 1 10.5 +1 1 2 15 +1 1 3 4.2 +1 2 1 5 +2 1 1 18 +1 2 2 10 +1 1 4 6.3 +1 1 5 1.6 +1 1 6 0.8 +1 1 7 1.0 +1 2 3 5 diff --git a/index.html b/index.html new file mode 100644 index 0000000..e6e3239 --- /dev/null +++ b/index.html @@ -0,0 +1,23 @@ + + + + Index of /ENS/2021-2sn-gls/CONTENU/MT/TP03 + + +

Index of /ENS/2021-2sn-gls/CONTENU/MT/TP03

+ + + + + + + + + + + + + +
[ICO]NameLast modifiedSizeDescription

[DIR]Parent Directory  -  
[TXT]Analyseur.java08-Nov-2021 10:01 1.6K 
[TXT]ExempleDeprecated.java08-Nov-2021 10:01 291  
[   ]ExempleDeprecated.javac08-Nov-2021 10:01 338  
[TXT]ExempleOverride.java08-Nov-2021 10:01 766  
[   ]ExempleOverride.javac08-Nov-2021 10:01 229  
[TXT]Position.java08-Nov-2021 10:01 363  
[TXT]StringBufferTest.java08-Nov-2021 10:01 579  
[   ]TP03-packages.jar23-Nov-2021 13:23 3.4K 
[   ]TP03.jar23-Nov-2021 13:23 3.3K 
[TXT]donnees.txt08-Nov-2021 10:01 104  

+
Apache/2.2.16 (Debian) DAV/2 SVN/1.6.12 PHP/5.3.3-7+squeeze29 with Suhosin-Patch Phusion_Passenger/3.0.7 Server at cregut.perso.enseeiht.fr Port 80
+ diff --git a/lombok.jar b/lombok.jar new file mode 100644 index 0000000..49f5286 Binary files /dev/null and b/lombok.jar differ diff --git a/sujet.html b/sujet.html new file mode 100644 index 0000000..009523a Binary files /dev/null and b/sujet.html differ