aboutsummaryrefslogtreecommitdiff
path: root/semestre 4/java/tme
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-02-16 10:16:31 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2026-02-16 10:16:31 +0100
commit2c530f2a58014e8e9479c41dabff9a639e9297a5 (patch)
treefe6f6890d983ff436d80e4194abf5545658f51d6 /semestre 4/java/tme
parentba6692d9b508b448eafd7bc71faa4ae3f3ac7199 (diff)
Cours du 02 au 13 févrierHEADmain
Diffstat (limited to 'semestre 4/java/tme')
-rw-r--r--semestre 4/java/tme/tp2/AdresseWeb.java23
-rw-r--r--semestre 4/java/tme/tp2/Complexe.java29
-rw-r--r--semestre 4/java/tme/tp2/Coureur.java53
-rw-r--r--semestre 4/java/tme/tp2/TestAdresseWeb.java7
-rw-r--r--semestre 4/java/tme/tp2/TestComplexe.java12
-rw-r--r--semestre 4/java/tme/tp2/TestCoureur.java16
-rw-r--r--semestre 4/java/tme/tp3/Cabine.java22
-rw-r--r--semestre 4/java/tme/tp3/Personne.java52
-rw-r--r--semestre 4/java/tme/tp3/Point.java38
-rw-r--r--semestre 4/java/tme/tp3/Roue.java15
-rw-r--r--semestre 4/java/tme/tp3/TestTracteur.java15
-rw-r--r--semestre 4/java/tme/tp3/TestTriangle.java18
-rw-r--r--semestre 4/java/tme/tp3/Tracteur.java27
-rw-r--r--semestre 4/java/tme/tp3/Triangle.java30
14 files changed, 357 insertions, 0 deletions
diff --git a/semestre 4/java/tme/tp2/AdresseWeb.java b/semestre 4/java/tme/tp2/AdresseWeb.java
new file mode 100644
index 0000000..409b61c
--- /dev/null
+++ b/semestre 4/java/tme/tp2/AdresseWeb.java
@@ -0,0 +1,23 @@
+public class AdresseWeb {
+ private final String protocole;
+ private final String domaine;
+ private final String chemin;
+
+ public AdresseWeb(String proto, String dom, String path) {
+ protocole = proto;
+ domaine = dom;
+ chemin = path;
+ }
+
+ public AdresseWeb(String dom, String path) {
+ this("http", dom, path);
+ }
+
+ public AdresseWeb(String dom) {
+ this("http", dom, "");
+ }
+
+ public String toString() {
+ return protocole + "://www." + domaine + chemin;
+ }
+}
diff --git a/semestre 4/java/tme/tp2/Complexe.java b/semestre 4/java/tme/tp2/Complexe.java
new file mode 100644
index 0000000..afd6cee
--- /dev/null
+++ b/semestre 4/java/tme/tp2/Complexe.java
@@ -0,0 +1,29 @@
+public final class Complexe {
+ public final double reelle;
+ public final double imag;
+
+ public Complexe(double reelle, double imag) {
+ this.reelle = reelle;
+ this.imag = imag;
+ }
+
+ public Complexe() {
+ this(Math.random() * 4 - 2, Math.random() * 4 - 2);
+ }
+
+ public String toString() {
+ return String.format("%f + %fi", reelle, imag);
+ }
+
+ public boolean estReel() {
+ return imag == 0;
+ }
+
+ public Complexe addition(Complexe c) {
+ return new Complexe(reelle + c.reelle, imag + c.imag);
+ }
+
+ public Complexe multiplication(Complexe c) {
+ return new Complexe(reelle * c.reelle - imag * c.imag, reelle * c.reelle + imag * c.imag);
+ }
+}
diff --git a/semestre 4/java/tme/tp2/Coureur.java b/semestre 4/java/tme/tp2/Coureur.java
new file mode 100644
index 0000000..1e8ed99
--- /dev/null
+++ b/semestre 4/java/tme/tp2/Coureur.java
@@ -0,0 +1,53 @@
+public final class Coureur {
+ private int numDossard;
+ private double tempsAu100;
+ private boolean possedeTemoin;
+
+ public Coureur(int num) {
+ numDossard = num;
+ possedeTemoin = false;
+ tempsAu100 = Math.random() * (16-12) + 12;
+ }
+
+ public Coureur() {
+ this((int) (Math.random() * 999 + 1));
+ }
+
+ public int getNumDossard() {
+ return numDossard;
+ }
+
+ public double getTempsAu100() {
+ return tempsAu100;
+ }
+
+ public boolean getPossedeTemoin() {
+ return possedeTemoin;
+ }
+
+ public void setNumDossard(int num) {
+ numDossard = num;
+ }
+
+ public void setTempsAu100(double temps) {
+ tempsAu100 = temps;
+ }
+
+ public void setPossedeTemoin(boolean has) {
+ possedeTemoin = has;
+ }
+
+ public String toString() {
+ return String.format("Coureur %d tempsAu100 : %.1f au 100m possedeTemoin %s", numDossard, tempsAu100, possedeTemoin ? "oui" : "non");
+ }
+
+ public void passeTemoin(Coureur c) {
+ System.out.println("moi, coureur "+numDossard+", je passe le témoin au coureur "+c.numDossard);
+ c.possedeTemoin = true;
+ possedeTemoin = false;
+ }
+
+ public void courir() {
+ System.out.println("e suis le coureur "+numDossard+" et je cours");
+ }
+}
diff --git a/semestre 4/java/tme/tp2/TestAdresseWeb.java b/semestre 4/java/tme/tp2/TestAdresseWeb.java
new file mode 100644
index 0000000..8bb3833
--- /dev/null
+++ b/semestre 4/java/tme/tp2/TestAdresseWeb.java
@@ -0,0 +1,7 @@
+public class TestAdresseWeb {
+ public static void main(String[] args) {
+ System.out.println(new AdresseWeb("hey"));
+ System.out.println(new AdresseWeb("hey", "/"));
+ System.out.println(new AdresseWeb("https", "hey", "/"));
+ }
+}
diff --git a/semestre 4/java/tme/tp2/TestComplexe.java b/semestre 4/java/tme/tp2/TestComplexe.java
new file mode 100644
index 0000000..1be9c8e
--- /dev/null
+++ b/semestre 4/java/tme/tp2/TestComplexe.java
@@ -0,0 +1,12 @@
+public final class TestComplexe {
+ public static void main(String[] args) {
+ final Complexe[] cs = {new Complexe(), new Complexe(), new Complexe()};
+ for (var c : cs) System.out.println("real " + c.estReel());
+ for (var c1 : cs) {
+ for (var c2 : cs) {
+ System.out.println("(" + c1 + ") + (" + c2 + ") = " + c1.addition(c2));
+ System.out.println("(" + c1 + ") * (" + c2 + ") = " + c1.multiplication(c2));
+ }
+ }
+ }
+}
diff --git a/semestre 4/java/tme/tp2/TestCoureur.java b/semestre 4/java/tme/tp2/TestCoureur.java
new file mode 100644
index 0000000..284fc21
--- /dev/null
+++ b/semestre 4/java/tme/tp2/TestCoureur.java
@@ -0,0 +1,16 @@
+public class TestCoureur {
+ public static void main(String[] args) {
+ final var c1 = new Coureur();
+ final var c2 = new Coureur();
+ final var c3 = new Coureur();
+ final var c4 = new Coureur();
+ c1.courir();
+ c1.passeTemoin(c2);
+ c2.courir();
+ c2.passeTemoin(c3);
+ c3.courir();
+ c3.passeTemoin(c4);
+ c4.courir();
+ System.out.println("temps : " + (c1.getTempsAu100() + c2.getTempsAu100() + c3.getTempsAu100() + c4.getTempsAu100()));
+ }
+}
diff --git a/semestre 4/java/tme/tp3/Cabine.java b/semestre 4/java/tme/tp3/Cabine.java
new file mode 100644
index 0000000..2b65abe
--- /dev/null
+++ b/semestre 4/java/tme/tp3/Cabine.java
@@ -0,0 +1,22 @@
+public class Cabine {
+ private int volume;
+ private String couleur;
+
+ public Cabine(int vol, String col) {
+ volume = vol;
+ couleur = col;
+ }
+
+ public Cabine(Cabine cb) {
+ volume = cb.volume;
+ couleur = cb.couleur;
+ }
+
+ public String toString() {
+ return String.format("Cabine{%d, %s}", volume, couleur);
+ }
+
+ public void setCouleur(String col) {
+ couleur = col;
+ }
+}
diff --git a/semestre 4/java/tme/tp3/Personne.java b/semestre 4/java/tme/tp3/Personne.java
new file mode 100644
index 0000000..664bf60
--- /dev/null
+++ b/semestre 4/java/tme/tp3/Personne.java
@@ -0,0 +1,52 @@
+public class Personne {
+ public final String name;
+ private Personne conjoint;
+
+ public Personne(String n) {
+ name = n;
+ }
+
+ public Personne() {
+ this("Pers" + (char) ((int) (Math.random() * 26) + 'A'));
+ }
+
+ public String toString() {
+ return String.format("%s, %s", name, conjoint == null ? "célibataire" : "marié(e)");
+ }
+
+ public void epouser(Personne p) {
+ if (p.conjoint != null || conjoint != null || p == this) {
+ System.out.println(String.format(
+ "Le mariage de %s avec %s est impossible", this, p
+ ));
+ return;
+ }
+ System.out.println(String.format(
+ "%s se marie avec %s", this, p
+ ));
+ conjoint = p;
+ p.conjoint = this;
+ }
+
+ public void divorcer() {
+ if (conjoint == null) return;
+ System.out.println(String.format(
+ "%s divorce avec %s", this, conjoint
+ ));
+ conjoint.conjoint = null;
+ conjoint = null;
+ }
+
+ public static void main(String[] args) {
+ final var p1 = new Personne();
+ final var p2 = new Personne();
+ final var p3 = new Personne();
+
+ p1.epouser(p2);
+ p1.epouser(p3);
+ p3.epouser(p1);
+ p3.epouser(p3);
+ p1.divorcer();
+ p3.divorcer();
+ }
+}
diff --git a/semestre 4/java/tme/tp3/Point.java b/semestre 4/java/tme/tp3/Point.java
new file mode 100644
index 0000000..1fdf9fa
--- /dev/null
+++ b/semestre 4/java/tme/tp3/Point.java
@@ -0,0 +1,38 @@
+public class Point {
+ private int posX, posY;
+
+ public Point(int x, int y) {
+ posX = x;
+ posY = y;
+ }
+
+ public Point() {
+ posX = (int) (Math.random()*10);
+ posY = (int) (Math.random()*10);
+ }
+
+ public Point(Point p) {
+ posX = p.posX;
+ posY = p.posY;
+ }
+
+ public String toString() {
+ return String.format("(%d,%d)", posX, posY);
+ }
+
+ public double distance(Point p) {
+ return Math.sqrt(
+ (p.posX - posX)*(p.posX - posX) + (p.posY - posY)*(p.posY - posY)
+ );
+ }
+
+ public void deplaceToi(int x, int y) {
+ posX = x;
+ posY = y;
+ }
+
+ public boolean equals(Object o) {
+ if (!(o instanceof final Point p)) return false;
+ return posX == p.posX && posY == p.posY;
+ }
+}
diff --git a/semestre 4/java/tme/tp3/Roue.java b/semestre 4/java/tme/tp3/Roue.java
new file mode 100644
index 0000000..bcae13e
--- /dev/null
+++ b/semestre 4/java/tme/tp3/Roue.java
@@ -0,0 +1,15 @@
+public class Roue {
+ private int diametre;
+
+ public Roue(int d) {
+ diametre = d;
+ }
+
+ public Roue() {
+ diametre = 60;
+ }
+
+ public String toString() {
+ return String.format("Roue{%d}", diametre);
+ }
+}
diff --git a/semestre 4/java/tme/tp3/TestTracteur.java b/semestre 4/java/tme/tp3/TestTracteur.java
new file mode 100644
index 0000000..6dd4c75
--- /dev/null
+++ b/semestre 4/java/tme/tp3/TestTracteur.java
@@ -0,0 +1,15 @@
+public class TestTracteur {
+ public static void main(String[] args) {
+ final var r1 = new Roue();
+ final var r2 = new Roue();
+ final var gr1 = new Roue(120);
+ final var gr2 = new Roue(120);
+ final var cb = new Cabine(3, "bleue");
+
+ final var t1 = new Tracteur(cb, r1, r2, gr1, gr2);
+ System.out.println(t1);
+ final var t2 = new Tracteur(t1);
+ t2.peindre("rouge");
+ System.out.println(t2);
+ }
+}
diff --git a/semestre 4/java/tme/tp3/TestTriangle.java b/semestre 4/java/tme/tp3/TestTriangle.java
new file mode 100644
index 0000000..61aacaa
--- /dev/null
+++ b/semestre 4/java/tme/tp3/TestTriangle.java
@@ -0,0 +1,18 @@
+public class TestTriangle {
+ public static void main(String[] args) {
+ final var p1 = new Point();
+ final var p2 = new Point();
+ System.out.println(p1);
+ System.out.println(p2);
+
+ final var p3 = new Point();
+ final var t = new Triangle(p1, p2, p3);
+ System.out.println(t);
+ System.out.println(t.getPerimetre());
+
+ final var t2 = new Triangle(t);
+ p1.deplaceToi(0,0);
+ System.out.println(t);
+ System.out.println(t2);
+ }
+}
diff --git a/semestre 4/java/tme/tp3/Tracteur.java b/semestre 4/java/tme/tp3/Tracteur.java
new file mode 100644
index 0000000..07d152d
--- /dev/null
+++ b/semestre 4/java/tme/tp3/Tracteur.java
@@ -0,0 +1,27 @@
+public class Tracteur {
+ private Cabine cabine;
+ private Roue r1;
+ private Roue r2;
+ private Roue gr1;
+ private Roue gr2;
+
+ public Tracteur(Cabine cabine, Roue r1, Roue r2, Roue gr1, Roue gr2) {
+ this.cabine = cabine;
+ this.r1 = r1;
+ this.r2 = r2;
+ this.gr1 = gr1;
+ this.gr2 = gr2;
+ }
+
+ public Tracteur(Tracteur t) {
+ this(new Cabine(t.cabine), t.r1, t.r2, t.gr1, t.gr2);
+ }
+
+ public void peindre(String col) {
+ cabine.setCouleur(col);
+ }
+
+ public String toString() {
+ return String.format("Tracteur{%s, %s, %s, %s, %s}", cabine, r1, r2, gr1, gr2);
+ }
+}
diff --git a/semestre 4/java/tme/tp3/Triangle.java b/semestre 4/java/tme/tp3/Triangle.java
new file mode 100644
index 0000000..d54835c
--- /dev/null
+++ b/semestre 4/java/tme/tp3/Triangle.java
@@ -0,0 +1,30 @@
+public class Triangle {
+ private Point p1, p2, p3;
+
+ public Triangle(Point p1, Point p2, Point p3) {
+ this.p1 = p1;
+ this.p2 = p2;
+ this.p3 = p3;
+ }
+
+ public Triangle() {
+ this(new Point(), new Point(), new Point());
+ }
+
+ public Triangle(Triangle t) {
+ this(new Point(t.p1), new Point(t.p2), new Point(t.p3));
+ }
+
+ public String toString() {
+ return String.format("{%s,%s,%s}", p1, p2, p3);
+ }
+
+ public double getPerimetre() {
+ return p1.distance(p2) + p2.distance(p3) + p3.distance(p1);
+ }
+
+ public boolean equals(Object o) {
+ if (!(o instanceof Triangle t)) return false;
+ return p1.equals(t.p1) && p2.equals(t.p2) && p3.equals(t.p3);
+ }
+}