TP07
This commit is contained in:
parent
422a41d232
commit
9441c8978a
BIN
DEV2.1/TP07/Etoile.class
Normal file
BIN
DEV2.1/TP07/Etoile.class
Normal file
Binary file not shown.
34
DEV2.1/TP07/Etoile.java
Normal file
34
DEV2.1/TP07/Etoile.java
Normal file
@ -0,0 +1,34 @@
|
||||
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;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Etoile e = new Etoile();
|
||||
while (e.suivant() != null) {
|
||||
// TODO
|
||||
System.out.println("Test");
|
||||
}
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP07/Moto.class
Normal file
BIN
DEV2.1/TP07/Moto.class
Normal file
Binary file not shown.
11
DEV2.1/TP07/Moto.java
Normal file
11
DEV2.1/TP07/Moto.java
Normal file
@ -0,0 +1,11 @@
|
||||
public class Moto implements Vehicule {
|
||||
|
||||
public String sorte() {
|
||||
return "Moto";
|
||||
}
|
||||
|
||||
public int nbRoues() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
BIN
DEV2.1/TP07/Moyenne.class
Normal file
BIN
DEV2.1/TP07/Moyenne.class
Normal file
Binary file not shown.
28
DEV2.1/TP07/Moyenne.java
Normal file
28
DEV2.1/TP07/Moyenne.java
Normal file
@ -0,0 +1,28 @@
|
||||
public class Moyenne {
|
||||
private double moyenne;
|
||||
private int compteur;
|
||||
|
||||
public Moyenne() {
|
||||
this.moyenne = 0;
|
||||
this.compteur = 0;
|
||||
}
|
||||
|
||||
public double add(Number n) {
|
||||
this.compteur++;
|
||||
return this.moyenne += n.doubleValue();
|
||||
}
|
||||
|
||||
public double getAverage() {
|
||||
return this.moyenne / this.compteur;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
Moyenne m = new Moyenne();
|
||||
m.add(2);
|
||||
m.add(5.4);
|
||||
m.add(547L);
|
||||
System.out.println(m.getAverage());
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP07/MoyenneV1.class
Normal file
BIN
DEV2.1/TP07/MoyenneV1.class
Normal file
Binary file not shown.
53
DEV2.1/TP07/MoyenneV1.java
Normal file
53
DEV2.1/TP07/MoyenneV1.java
Normal file
@ -0,0 +1,53 @@
|
||||
public class MoyenneV1 {
|
||||
private double moyenne;
|
||||
private int compteur;
|
||||
|
||||
public MoyenneV1() {
|
||||
this.moyenne = 0;
|
||||
this.compteur = 0;
|
||||
}
|
||||
|
||||
public double add(byte n) {
|
||||
this.compteur++;
|
||||
return this.moyenne += n;
|
||||
}
|
||||
|
||||
public double add(short n) {
|
||||
this.compteur++;
|
||||
return this.moyenne += n;
|
||||
}
|
||||
|
||||
public double add(int n) {
|
||||
this.compteur++;
|
||||
return this.moyenne += n;
|
||||
}
|
||||
|
||||
public double add(long n) {
|
||||
this.compteur++;
|
||||
return this.moyenne += n;
|
||||
}
|
||||
|
||||
public double add(float n) {
|
||||
this.compteur++;
|
||||
return this.moyenne += n;
|
||||
}
|
||||
|
||||
public double add(double n) {
|
||||
this.compteur++;
|
||||
return this.moyenne += n;
|
||||
}
|
||||
|
||||
public double getAverage() {
|
||||
return this.moyenne / this.compteur;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
MoyenneV1 m = new MoyenneV1();
|
||||
m.add(2);
|
||||
m.add(5.4);
|
||||
m.add(547L);
|
||||
System.out.println(m.getAverage());
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP07/ProducteurDePoints.class
Normal file
BIN
DEV2.1/TP07/ProducteurDePoints.class
Normal file
Binary file not shown.
5
DEV2.1/TP07/ProducteurDePoints.java
Normal file
5
DEV2.1/TP07/ProducteurDePoints.java
Normal file
@ -0,0 +1,5 @@
|
||||
import java.awt.Point;
|
||||
|
||||
public interface ProducteurDePoints {
|
||||
Point suivant();
|
||||
}
|
BIN
DEV2.1/TP07/Test.class
Normal file
BIN
DEV2.1/TP07/Test.class
Normal file
Binary file not shown.
22
DEV2.1/TP07/Test.java
Normal file
22
DEV2.1/TP07/Test.java
Normal file
@ -0,0 +1,22 @@
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
public class Test {
|
||||
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/TP07/Vehicule.class
Normal file
BIN
DEV2.1/TP07/Vehicule.class
Normal file
Binary file not shown.
6
DEV2.1/TP07/Vehicule.java
Normal file
6
DEV2.1/TP07/Vehicule.java
Normal file
@ -0,0 +1,6 @@
|
||||
public interface Vehicule {
|
||||
|
||||
public String sorte();
|
||||
|
||||
public int nbRoues();
|
||||
}
|
BIN
DEV2.1/TP07/Voiture.class
Normal file
BIN
DEV2.1/TP07/Voiture.class
Normal file
Binary file not shown.
11
DEV2.1/TP07/Voiture.java
Normal file
11
DEV2.1/TP07/Voiture.java
Normal file
@ -0,0 +1,11 @@
|
||||
public class Voiture implements Vehicule {
|
||||
|
||||
public String sorte() {
|
||||
return "Voiture";
|
||||
}
|
||||
|
||||
public int nbRoues() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user