diff --git a/DEV2.1/TP5:MiseEnPageEtDessin/Sautoir.class b/DEV2.1/TP5:MiseEnPageEtDessin/Sautoir.class new file mode 100644 index 0000000..c086cf0 Binary files /dev/null and b/DEV2.1/TP5:MiseEnPageEtDessin/Sautoir.class differ diff --git a/DEV2.1/TP5:MiseEnPageEtDessin/Sautoir.java b/DEV2.1/TP5:MiseEnPageEtDessin/Sautoir.java index 13ce3b2..66dac1c 100644 --- a/DEV2.1/TP5:MiseEnPageEtDessin/Sautoir.java +++ b/DEV2.1/TP5:MiseEnPageEtDessin/Sautoir.java @@ -4,7 +4,18 @@ import java.awt.*; public class Sautoir extends JComponent{ protected void paintComponent(Graphics pinceau) { - // obligatoire : on crée un nouveau pinceau pour pouvoir le modifier plus tard - Graphics pinceau = pinceau.create(); - pinceau.setColor(Color.CYAN); - pinceau.fillPolygon([0,0],[50,0],3); \ No newline at end of file + // obligatoire : on cree un nouveau pinceau pour pouvoir le modifier plus tard + Graphics pinceau2 = pinceau.create(); + if (this.isOpaque()) { + // obligatoire : on repeint toute la surface avec la couleur de fond + pinceau2.setColor(this.getBackground()); + pinceau2.fillRect(0, 0, this.getWidth(), this.getHeight()); + } + pinceau2.setColor(Color.CYAN); + int[] x={0, getWidth()/2, getWidth()}; + int[] yt={0, getHeight()/2, 0}; + pinceau2.fillPolygon(x,yt,3); + int[] yb={ getHeight(), getHeight()/2, getHeight()}; + pinceau2.fillPolygon(x,yb,3); + } +} diff --git a/DEV2.1/TP6 b/DEV2.1/TP6 new file mode 100644 index 0000000..e69de29 diff --git a/DEV2.1/TP6:Polymorphisme/MainVehicule.class b/DEV2.1/TP6:Polymorphisme/MainVehicule.class new file mode 100644 index 0000000..2a49f90 Binary files /dev/null and b/DEV2.1/TP6:Polymorphisme/MainVehicule.class differ diff --git a/DEV2.1/TP6:Polymorphisme/MainVehicule.java b/DEV2.1/TP6:Polymorphisme/MainVehicule.java new file mode 100644 index 0000000..e773aba --- /dev/null +++ b/DEV2.1/TP6:Polymorphisme/MainVehicule.java @@ -0,0 +1,22 @@ +import javax.swing.JOptionPane; + +public class MainVehicule{ + 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/DEV2.1/TP6:Polymorphisme/Moto.class b/DEV2.1/TP6:Polymorphisme/Moto.class new file mode 100644 index 0000000..8c054d8 Binary files /dev/null and b/DEV2.1/TP6:Polymorphisme/Moto.class differ diff --git a/DEV2.1/TP6:Polymorphisme/Moto.java b/DEV2.1/TP6:Polymorphisme/Moto.java new file mode 100644 index 0000000..f1ff095 --- /dev/null +++ b/DEV2.1/TP6:Polymorphisme/Moto.java @@ -0,0 +1,5 @@ +public class Moto extends VehiculeAbstract{ + public Moto(){ + super(2,"Moto"); + } +} \ No newline at end of file diff --git a/DEV2.1/TP6:Polymorphisme/Moyenne.class b/DEV2.1/TP6:Polymorphisme/Moyenne.class new file mode 100644 index 0000000..9bef0cd Binary files /dev/null and b/DEV2.1/TP6:Polymorphisme/Moyenne.class differ diff --git a/DEV2.1/TP6:Polymorphisme/Moyenne.java b/DEV2.1/TP6:Polymorphisme/Moyenne.java new file mode 100644 index 0000000..a0f3f05 --- /dev/null +++ b/DEV2.1/TP6:Polymorphisme/Moyenne.java @@ -0,0 +1,23 @@ +public class Moyenne{ + private double total=0; + private long cpt=0; + + public void add(Number val){ + total += val.doubleValue(); + ++cpt; + } + + public double getAverage(){ + if (cpt==0){ + return 0; + } + return total/cpt; + } + + public static void main(String[] args) { + Moyenne m = new Moyenne(); + m.add(5.5); + m.add(10); + System.out.println(m.getAverage()); + } +} \ No newline at end of file diff --git a/DEV2.1/TP6:Polymorphisme/Vehicule.class b/DEV2.1/TP6:Polymorphisme/Vehicule.class new file mode 100644 index 0000000..a9f0cdb Binary files /dev/null and b/DEV2.1/TP6:Polymorphisme/Vehicule.class differ diff --git a/DEV2.1/TP6:Polymorphisme/Vehicule.java b/DEV2.1/TP6:Polymorphisme/Vehicule.java new file mode 100644 index 0000000..e7edc06 --- /dev/null +++ b/DEV2.1/TP6:Polymorphisme/Vehicule.java @@ -0,0 +1,4 @@ +public interface Vehicule{ + int nbRoues(); + String sorte(); +} \ No newline at end of file diff --git a/DEV2.1/TP6:Polymorphisme/VehiculeAbstract.class b/DEV2.1/TP6:Polymorphisme/VehiculeAbstract.class new file mode 100644 index 0000000..5061935 Binary files /dev/null and b/DEV2.1/TP6:Polymorphisme/VehiculeAbstract.class differ diff --git a/DEV2.1/TP6:Polymorphisme/VehiculeAbstract.java b/DEV2.1/TP6:Polymorphisme/VehiculeAbstract.java new file mode 100644 index 0000000..b1e7065 --- /dev/null +++ b/DEV2.1/TP6:Polymorphisme/VehiculeAbstract.java @@ -0,0 +1,18 @@ +public abstract class VehiculeAbstract implements Vehicule{ + + private int nbRoues; + private String sorte; + + public VehiculeAbstract(int nbRoues, String sorte){ + this.nbRoues=nbRoues; + this.sorte=sorte; + } + + public int nbRoues(){ + return nbRoues; + } + + public String sorte(){ + return sorte; + } +} \ No newline at end of file diff --git a/DEV2.1/TP6:Polymorphisme/Voiture.class b/DEV2.1/TP6:Polymorphisme/Voiture.class new file mode 100644 index 0000000..e041b80 Binary files /dev/null and b/DEV2.1/TP6:Polymorphisme/Voiture.class differ diff --git a/DEV2.1/TP6:Polymorphisme/Voiture.java b/DEV2.1/TP6:Polymorphisme/Voiture.java new file mode 100644 index 0000000..f81b227 --- /dev/null +++ b/DEV2.1/TP6:Polymorphisme/Voiture.java @@ -0,0 +1,5 @@ +public class Voiture extends VehiculeAbstract{ + public Voiture(){ + super(4,"Voiture"); + } +} \ No newline at end of file