27 Mars
This commit is contained in:
parent
d14f7c23c6
commit
0c873faeb2
BIN
DEV2.1/TP5:MiseEnPageEtDessin/Sautoir.class
Normal file
BIN
DEV2.1/TP5:MiseEnPageEtDessin/Sautoir.class
Normal file
Binary file not shown.
@ -4,7 +4,18 @@ import java.awt.*;
|
|||||||
public class Sautoir extends JComponent{
|
public class Sautoir extends JComponent{
|
||||||
|
|
||||||
protected void paintComponent(Graphics pinceau) {
|
protected void paintComponent(Graphics pinceau) {
|
||||||
// obligatoire : on crée un nouveau pinceau pour pouvoir le modifier plus tard
|
// obligatoire : on cree un nouveau pinceau pour pouvoir le modifier plus tard
|
||||||
Graphics pinceau = pinceau.create();
|
Graphics pinceau2 = pinceau.create();
|
||||||
pinceau.setColor(Color.CYAN);
|
if (this.isOpaque()) {
|
||||||
pinceau.fillPolygon([0,0],[50,0],3);
|
// 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
0
DEV2.1/TP6
Normal file
0
DEV2.1/TP6
Normal file
BIN
DEV2.1/TP6:Polymorphisme/MainVehicule.class
Normal file
BIN
DEV2.1/TP6:Polymorphisme/MainVehicule.class
Normal file
Binary file not shown.
22
DEV2.1/TP6:Polymorphisme/MainVehicule.java
Normal file
22
DEV2.1/TP6:Polymorphisme/MainVehicule.java
Normal file
@ -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.");
|
||||||
|
}
|
||||||
|
}
|
BIN
DEV2.1/TP6:Polymorphisme/Moto.class
Normal file
BIN
DEV2.1/TP6:Polymorphisme/Moto.class
Normal file
Binary file not shown.
5
DEV2.1/TP6:Polymorphisme/Moto.java
Normal file
5
DEV2.1/TP6:Polymorphisme/Moto.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
public class Moto extends VehiculeAbstract{
|
||||||
|
public Moto(){
|
||||||
|
super(2,"Moto");
|
||||||
|
}
|
||||||
|
}
|
BIN
DEV2.1/TP6:Polymorphisme/Moyenne.class
Normal file
BIN
DEV2.1/TP6:Polymorphisme/Moyenne.class
Normal file
Binary file not shown.
23
DEV2.1/TP6:Polymorphisme/Moyenne.java
Normal file
23
DEV2.1/TP6:Polymorphisme/Moyenne.java
Normal file
@ -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());
|
||||||
|
}
|
||||||
|
}
|
BIN
DEV2.1/TP6:Polymorphisme/Vehicule.class
Normal file
BIN
DEV2.1/TP6:Polymorphisme/Vehicule.class
Normal file
Binary file not shown.
4
DEV2.1/TP6:Polymorphisme/Vehicule.java
Normal file
4
DEV2.1/TP6:Polymorphisme/Vehicule.java
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
public interface Vehicule{
|
||||||
|
int nbRoues();
|
||||||
|
String sorte();
|
||||||
|
}
|
BIN
DEV2.1/TP6:Polymorphisme/VehiculeAbstract.class
Normal file
BIN
DEV2.1/TP6:Polymorphisme/VehiculeAbstract.class
Normal file
Binary file not shown.
18
DEV2.1/TP6:Polymorphisme/VehiculeAbstract.java
Normal file
18
DEV2.1/TP6:Polymorphisme/VehiculeAbstract.java
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
BIN
DEV2.1/TP6:Polymorphisme/Voiture.class
Normal file
BIN
DEV2.1/TP6:Polymorphisme/Voiture.class
Normal file
Binary file not shown.
5
DEV2.1/TP6:Polymorphisme/Voiture.java
Normal file
5
DEV2.1/TP6:Polymorphisme/Voiture.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
public class Voiture extends VehiculeAbstract{
|
||||||
|
public Voiture(){
|
||||||
|
super(4,"Voiture");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user