diff --git a/APL2.1/TP08/Moyenne/Moyenne.class b/APL2.1/TP08/Moyenne/Moyenne.class new file mode 100644 index 0000000..5915053 Binary files /dev/null and b/APL2.1/TP08/Moyenne/Moyenne.class differ diff --git a/APL2.1/TP08/Moyenne/Moyenne.java b/APL2.1/TP08/Moyenne/Moyenne.java new file mode 100644 index 0000000..bca8a34 --- /dev/null +++ b/APL2.1/TP08/Moyenne/Moyenne.java @@ -0,0 +1,18 @@ +public class Moyenne { + private int count; + private double sum; + + public Moyenne() { + count = 0; + sum = 0; + } + + public void add(Number n) { + count++; + sum += n.doubleValue(); + } + + public double getAverage() { + return sum / (double)count; + } +} \ No newline at end of file diff --git a/APL2.1/TP08/Moyenne/TestMoyenne.class b/APL2.1/TP08/Moyenne/TestMoyenne.class new file mode 100644 index 0000000..6d89830 Binary files /dev/null and b/APL2.1/TP08/Moyenne/TestMoyenne.class differ diff --git a/APL2.1/TP08/Moyenne/TestMoyenne.java b/APL2.1/TP08/Moyenne/TestMoyenne.java new file mode 100644 index 0000000..f39242b --- /dev/null +++ b/APL2.1/TP08/Moyenne/TestMoyenne.java @@ -0,0 +1,12 @@ +public class TestMoyenne { + public static void main(String[] args) { + Moyenne m = new Moyenne(); + + m.add(1); + m.add(1.2f); + m.add(1.52d); + m.add(2); + + System.out.println(m.getAverage()); + } +} \ No newline at end of file diff --git a/APL2.1/TP08/Polyligne/Etoile.class b/APL2.1/TP08/Polyligne/Etoile.class new file mode 100644 index 0000000..3cc6c74 Binary files /dev/null and b/APL2.1/TP08/Polyligne/Etoile.class differ diff --git a/APL2.1/TP08/Polyligne/Etoile.java b/APL2.1/TP08/Polyligne/Etoile.java new file mode 100644 index 0000000..bad5e8f --- /dev/null +++ b/APL2.1/TP08/Polyligne/Etoile.java @@ -0,0 +1,26 @@ +import java.awt.Point; + +public class Etoile implements ProducteurDePoints { + private static final int xCentre = 100; + private static final int yCentre = 100; + private static final double rayon = 90.0; + private static final double angleDepart = Math.PI/4.0; + private static final double angleIncrement = (4.0*Math.PI)/5.0; + private double numero; + public Etoile() { + this.numero = 0.0; + } + public Point suivant() { + Point p = null; + if (this.numero < 6.0) { + double angle = Etoile.angleDepart+this.numero*Etoile.angleIncrement; + p = new Point((int) (Etoile.rayon*Math.cos(angle)), + (int) (Etoile.rayon*Math.sin(angle))); + p.translate(Etoile.xCentre, Etoile.yCentre); + this.numero++; + } else { + this.numero = 0.0; + } + return p; + } +} \ No newline at end of file diff --git a/APL2.1/TP08/Polyligne/Polyligne.class b/APL2.1/TP08/Polyligne/Polyligne.class new file mode 100644 index 0000000..d6173d6 Binary files /dev/null and b/APL2.1/TP08/Polyligne/Polyligne.class differ diff --git a/APL2.1/TP08/Polyligne/Polyligne.java b/APL2.1/TP08/Polyligne/Polyligne.java new file mode 100644 index 0000000..6862197 --- /dev/null +++ b/APL2.1/TP08/Polyligne/Polyligne.java @@ -0,0 +1,39 @@ +import java.awt.*; +import javax.swing.*; + +public class Polyligne extends JComponent { + Point p1; + Point p2; + + ProducteurDePoints pp; + + public Polyligne(ProducteurDePoints arg) { + super(); + pp = arg; + } + + @Override + protected void paintComponent(Graphics brush) { + Graphics newBrush = brush.create(); + + if (this.isOpaque()) { + newBrush.setColor(this.getBackground()); + newBrush.fillRect(0, 0, this.getWidth(), this.getHeight()); + } + + newBrush.setColor(Color.BLACK); + System.out.println("Test"); + + while (true) { + if (p1 != null) { + newBrush.drawLine(p1.x, p1.y, p2.x, p2.y); + p1 = p2; + p2 = pp.suivant(); + if (p2 == null) break; + } else { + p1 = pp.suivant(); + p2 = pp.suivant(); + } + } + } +} \ No newline at end of file diff --git a/APL2.1/TP08/Polyligne/ProducteurDePoints.class b/APL2.1/TP08/Polyligne/ProducteurDePoints.class new file mode 100644 index 0000000..d02e050 Binary files /dev/null and b/APL2.1/TP08/Polyligne/ProducteurDePoints.class differ diff --git a/APL2.1/TP08/Polyligne/ProducteurDePoints.java b/APL2.1/TP08/Polyligne/ProducteurDePoints.java new file mode 100644 index 0000000..4c0dd33 --- /dev/null +++ b/APL2.1/TP08/Polyligne/ProducteurDePoints.java @@ -0,0 +1,5 @@ +import java.awt.Point; + +public interface ProducteurDePoints { + Point suivant(); +} \ No newline at end of file diff --git a/APL2.1/TP08/Polyligne/Spirale.class b/APL2.1/TP08/Polyligne/Spirale.class new file mode 100644 index 0000000..91a58d7 Binary files /dev/null and b/APL2.1/TP08/Polyligne/Spirale.class differ diff --git a/APL2.1/TP08/Polyligne/Spirale.java b/APL2.1/TP08/Polyligne/Spirale.java new file mode 100644 index 0000000..9088f89 --- /dev/null +++ b/APL2.1/TP08/Polyligne/Spirale.java @@ -0,0 +1,34 @@ +import java.awt.Point; + +public class Spirale implements ProducteurDePoints { + private static final int centreX = 100; + private static final int centreY = 100; + private static final double rayon = 90.0; + private static final double radiusIncrement = -0.1; + private static final double angleDepart = 0.0; + private static final double angleIncrement = Math.PI / 30; + + private double angle; + private double curRadius; + public Spirale() { + angle = angleDepart; + curRadius = rayon; + } + + public Point suivant() { + Point p = null; + angle += angleIncrement; + curRadius += radiusIncrement; + + if (curRadius > 0.0) { + p = new Point( + (int)(Math.cos(angle) * curRadius), + (int)(Math.sin(angle) * curRadius) + ); + + p.translate(centreX, centreY); + } + + return p; + } +} \ No newline at end of file diff --git a/APL2.1/TP08/Polyligne/Test.class b/APL2.1/TP08/Polyligne/Test.class new file mode 100644 index 0000000..de32622 Binary files /dev/null and b/APL2.1/TP08/Polyligne/Test.class differ diff --git a/APL2.1/TP08/Polyligne/Test.java b/APL2.1/TP08/Polyligne/Test.java new file mode 100644 index 0000000..474e9da --- /dev/null +++ b/APL2.1/TP08/Polyligne/Test.java @@ -0,0 +1,20 @@ +import java.awt.*; +import javax.swing.*; + +public class Test { + public static void main(String[] args) { + JFrame f = new JFrame(); + f.setSize(250, 250); + f.setLocation(100, 100); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + f.setLayout(null); + + Spirale e = new Spirale(); + Polyligne pl = new Polyligne(e); + pl.setSize(230, 230); + pl.setLocation(0, 0); + f.add(pl); + + f.setVisible(true); + } +} \ No newline at end of file diff --git a/APL2.1/TP08/Véhicules/Moto.class b/APL2.1/TP08/Véhicules/Moto.class new file mode 100644 index 0000000..c833b93 Binary files /dev/null and b/APL2.1/TP08/Véhicules/Moto.class differ diff --git a/APL2.1/TP08/Véhicules/Moto.java b/APL2.1/TP08/Véhicules/Moto.java new file mode 100644 index 0000000..ad240e1 --- /dev/null +++ b/APL2.1/TP08/Véhicules/Moto.java @@ -0,0 +1,6 @@ +public class Moto extends Vehicule { + public Moto() { + this.wheels = 2; + this.type = "Moto"; + } +} \ No newline at end of file diff --git a/APL2.1/TP08/Véhicules/Vehicule.class b/APL2.1/TP08/Véhicules/Vehicule.class new file mode 100644 index 0000000..4a7c2aa Binary files /dev/null and b/APL2.1/TP08/Véhicules/Vehicule.class differ diff --git a/APL2.1/TP08/Véhicules/Vehicule.java b/APL2.1/TP08/Véhicules/Vehicule.java new file mode 100644 index 0000000..d8635e7 --- /dev/null +++ b/APL2.1/TP08/Véhicules/Vehicule.java @@ -0,0 +1,12 @@ +public abstract class Vehicule { + protected int wheels; + protected String type; + + public int nbRoues() { + return this.wheels; + } + + public String sorte() { + return this.type; + } +} \ No newline at end of file diff --git a/APL2.1/TP08/Véhicules/Vehicules.class b/APL2.1/TP08/Véhicules/Vehicules.class new file mode 100644 index 0000000..33dadc7 Binary files /dev/null and b/APL2.1/TP08/Véhicules/Vehicules.class differ diff --git a/APL2.1/TP08/Véhicules/Vehicules.java b/APL2.1/TP08/Véhicules/Vehicules.java new file mode 100644 index 0000000..e27de37 --- /dev/null +++ b/APL2.1/TP08/Véhicules/Vehicules.java @@ -0,0 +1,22 @@ +import javax.swing.JOptionPane; + +public class Vehicules { + public static void main(String[] args) { + Vehicule v; + Object[] choix = {"Voiture", "Moto"}; + + int reponse = JOptionPane.showOptionDialog(null, + "Quel v\u00E9hicule choisissez-vous ?", + "Question", + JOptionPane.DEFAULT_OPTION, + JOptionPane.QUESTION_MESSAGE, + null, + choix, + null); + if (reponse == 0) + v = new Voiture(); + else + v = new Moto(); + System.out.println("Une "+v.sorte()+" poss\u00E8de "+v.nbRoues()+" roues."); + } +} \ No newline at end of file diff --git a/APL2.1/TP08/Véhicules/Voiture.class b/APL2.1/TP08/Véhicules/Voiture.class new file mode 100644 index 0000000..0e8f321 Binary files /dev/null and b/APL2.1/TP08/Véhicules/Voiture.class differ diff --git a/APL2.1/TP08/Véhicules/Voiture.java b/APL2.1/TP08/Véhicules/Voiture.java new file mode 100644 index 0000000..7db37a6 --- /dev/null +++ b/APL2.1/TP08/Véhicules/Voiture.java @@ -0,0 +1,6 @@ +public class Voiture extends Vehicule { + public Voiture() { + this.wheels = 4; + this.type = "Voiture"; + } +} \ No newline at end of file