This commit is contained in:
Adrian POURCHOT 2023-03-27 11:28:45 +02:00
parent d14f7c23c6
commit 0c873faeb2
15 changed files with 92 additions and 4 deletions

Binary file not shown.

View File

@ -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);
// 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);
}
}

0
DEV2.1/TP6 Normal file
View File

Binary file not shown.

View 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.");
}
}

Binary file not shown.

View File

@ -0,0 +1,5 @@
public class Moto extends VehiculeAbstract{
public Moto(){
super(2,"Moto");
}
}

Binary file not shown.

View 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());
}
}

Binary file not shown.

View File

@ -0,0 +1,4 @@
public interface Vehicule{
int nbRoues();
String sorte();
}

Binary file not shown.

View 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;
}
}

Binary file not shown.

View File

@ -0,0 +1,5 @@
public class Voiture extends VehiculeAbstract{
public Voiture(){
super(4,"Voiture");
}
}