Merge remote-tracking branch 'tp3/master'
This commit is contained in:
commit
76d5941773
56
Analyseur.java
Normal file
56
Analyseur.java
Normal file
|
@ -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<Position, Double> 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<Position, Double> 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);
|
||||||
|
}
|
||||||
|
}
|
31
ExempleDeprecated.java
Normal file
31
ExempleDeprecated.java
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
10
ExempleDeprecated.javac
Normal file
10
ExempleDeprecated.javac
Normal file
|
@ -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
|
36
ExempleOverride.java
Normal file
36
ExempleOverride.java
Normal file
|
@ -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());
|
||||||
|
} }
|
7
ExempleOverride.javac
Normal file
7
ExempleOverride.javac
Normal file
|
@ -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
|
47
Position.java
Normal file
47
Position.java
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
29
StringBufferTest.java
Normal file
29
StringBufferTest.java
Normal file
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
BIN
TP03-packages.jar
Normal file
BIN
TP03-packages.jar
Normal file
Binary file not shown.
11
donnees.txt
Normal file
11
donnees.txt
Normal file
|
@ -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
|
23
index.html
Normal file
23
index.html
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Index of /ENS/2021-2sn-gls/CONTENU/MT/TP03</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Index of /ENS/2021-2sn-gls/CONTENU/MT/TP03</h1>
|
||||||
|
<table><tr><th><img src="/icons/blank.gif" alt="[ICO]"></th><th><a href="?C=N;O=D">Name</a></th><th><a href="?C=M;O=A">Last modified</a></th><th><a href="?C=S;O=A">Size</a></th><th><a href="?C=D;O=A">Description</a></th></tr><tr><th colspan="5"><hr></th></tr>
|
||||||
|
<tr><td valign="top"><img src="/icons/back.gif" alt="[DIR]"></td><td><a href="/ENS/2021-2sn-gls/CONTENU/MT/">Parent Directory</a></td><td> </td><td align="right"> - </td><td> </td></tr>
|
||||||
|
<tr><td valign="top"><img src="/icons/text.gif" alt="[TXT]"></td><td><a href="Analyseur.java">Analyseur.java</a></td><td align="right">08-Nov-2021 10:01 </td><td align="right">1.6K</td><td> </td></tr>
|
||||||
|
<tr><td valign="top"><img src="/icons/text.gif" alt="[TXT]"></td><td><a href="ExempleDeprecated.java">ExempleDeprecated.java</a></td><td align="right">08-Nov-2021 10:01 </td><td align="right">291 </td><td> </td></tr>
|
||||||
|
<tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="ExempleDeprecated.javac">ExempleDeprecated.javac</a></td><td align="right">08-Nov-2021 10:01 </td><td align="right">338 </td><td> </td></tr>
|
||||||
|
<tr><td valign="top"><img src="/icons/text.gif" alt="[TXT]"></td><td><a href="ExempleOverride.java">ExempleOverride.java</a></td><td align="right">08-Nov-2021 10:01 </td><td align="right">766 </td><td> </td></tr>
|
||||||
|
<tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="ExempleOverride.javac">ExempleOverride.javac</a></td><td align="right">08-Nov-2021 10:01 </td><td align="right">229 </td><td> </td></tr>
|
||||||
|
<tr><td valign="top"><img src="/icons/text.gif" alt="[TXT]"></td><td><a href="Position.java">Position.java</a></td><td align="right">08-Nov-2021 10:01 </td><td align="right">363 </td><td> </td></tr>
|
||||||
|
<tr><td valign="top"><img src="/icons/text.gif" alt="[TXT]"></td><td><a href="StringBufferTest.java">StringBufferTest.java</a></td><td align="right">08-Nov-2021 10:01 </td><td align="right">579 </td><td> </td></tr>
|
||||||
|
<tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="TP03-packages.jar">TP03-packages.jar</a></td><td align="right">23-Nov-2021 13:23 </td><td align="right">3.4K</td><td> </td></tr>
|
||||||
|
<tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="TP03.jar">TP03.jar</a></td><td align="right">23-Nov-2021 13:23 </td><td align="right">3.3K</td><td> </td></tr>
|
||||||
|
<tr><td valign="top"><img src="/icons/text.gif" alt="[TXT]"></td><td><a href="donnees.txt">donnees.txt</a></td><td align="right">08-Nov-2021 10:01 </td><td align="right">104 </td><td> </td></tr>
|
||||||
|
<tr><th colspan="5"><hr></th></tr>
|
||||||
|
</table>
|
||||||
|
<address>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</address>
|
||||||
|
</body></html>
|
BIN
lombok.jar
Normal file
BIN
lombok.jar
Normal file
Binary file not shown.
BIN
sujet.html
Normal file
BIN
sujet.html
Normal file
Binary file not shown.
Loading…
Reference in a new issue