update
This commit is contained in:
10
DEV/DEV2.1/TP07_Polymorphisme/Moto.java~
Normal file
10
DEV/DEV2.1/TP07_Polymorphisme/Moto.java~
Normal file
@@ -0,0 +1,10 @@
|
||||
public class Moto implements Vehicule{
|
||||
@Override
|
||||
public int nbRoues(){
|
||||
return 1;
|
||||
}
|
||||
@Override
|
||||
public String sorte(){
|
||||
return "Ayoub fait du 6 roue";
|
||||
}
|
||||
}
|
||||
0
DEV/DEV2.1/TP07_Polymorphisme/Moyenne1.java~
Normal file
0
DEV/DEV2.1/TP07_Polymorphisme/Moyenne1.java~
Normal file
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q1_Vehicule/Moto.class
Normal file
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q1_Vehicule/Moto.class
Normal file
Binary file not shown.
10
DEV/DEV2.1/TP07_Polymorphisme/Q1_Vehicule/Moto.java
Normal file
10
DEV/DEV2.1/TP07_Polymorphisme/Q1_Vehicule/Moto.java
Normal file
@@ -0,0 +1,10 @@
|
||||
public class Moto implements Vehicule{
|
||||
@Override
|
||||
public int nbRoues(){
|
||||
return 1;
|
||||
}
|
||||
@Override
|
||||
public String sorte(){
|
||||
return "bcaene";
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q1_Vehicule/Test.class
Normal file
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q1_Vehicule/Test.class
Normal file
Binary file not shown.
22
DEV/DEV2.1/TP07_Polymorphisme/Q1_Vehicule/Test.java
Normal file
22
DEV/DEV2.1/TP07_Polymorphisme/Q1_Vehicule/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
DEV/DEV2.1/TP07_Polymorphisme/Q1_Vehicule/Vehicule.class
Normal file
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q1_Vehicule/Vehicule.class
Normal file
Binary file not shown.
4
DEV/DEV2.1/TP07_Polymorphisme/Q1_Vehicule/Vehicule.java
Normal file
4
DEV/DEV2.1/TP07_Polymorphisme/Q1_Vehicule/Vehicule.java
Normal file
@@ -0,0 +1,4 @@
|
||||
public interface Vehicule{
|
||||
int nbRoues();
|
||||
String sorte();
|
||||
}
|
||||
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q1_Vehicule/Voiture.class
Normal file
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q1_Vehicule/Voiture.class
Normal file
Binary file not shown.
10
DEV/DEV2.1/TP07_Polymorphisme/Q1_Vehicule/Voiture.java
Normal file
10
DEV/DEV2.1/TP07_Polymorphisme/Q1_Vehicule/Voiture.java
Normal file
@@ -0,0 +1,10 @@
|
||||
public class Voiture implements Vehicule{
|
||||
@Override
|
||||
public int nbRoues(){
|
||||
return 4;
|
||||
}
|
||||
@Override
|
||||
public String sorte(){
|
||||
return "vuitore";
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q2_Moyenne/Moyenne1.class
Normal file
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q2_Moyenne/Moyenne1.class
Normal file
Binary file not shown.
35
DEV/DEV2.1/TP07_Polymorphisme/Q2_Moyenne/Moyenne1.java
Normal file
35
DEV/DEV2.1/TP07_Polymorphisme/Q2_Moyenne/Moyenne1.java
Normal file
@@ -0,0 +1,35 @@
|
||||
public class Moyenne1{
|
||||
double total;
|
||||
int nbValeur;
|
||||
public Moyenne1(){
|
||||
this.nbValeur = 0;
|
||||
this.total = 0;
|
||||
}
|
||||
public void add(byte valeur){
|
||||
this.nbValeur ++;
|
||||
this.total = this.total + valeur;
|
||||
}
|
||||
public void add(short valeur){
|
||||
this.nbValeur ++;
|
||||
this.total = this.total + valeur;
|
||||
}
|
||||
public void add(int valeur){
|
||||
this.nbValeur ++;
|
||||
this.total = this.total + valeur;
|
||||
}
|
||||
public void add(long valeur){
|
||||
this.nbValeur ++;
|
||||
this.total = this.total + valeur;
|
||||
}
|
||||
public void add(float valeur){
|
||||
this.nbValeur ++;
|
||||
this.total = this.total + valeur;
|
||||
}
|
||||
public void add(double valeur){
|
||||
this.nbValeur ++;
|
||||
this.total = this.total + valeur;
|
||||
}
|
||||
public double getAverage(){
|
||||
return this.total/this.nbValeur;
|
||||
}
|
||||
}
|
||||
35
DEV/DEV2.1/TP07_Polymorphisme/Q2_Moyenne/Moyenne1.java~
Normal file
35
DEV/DEV2.1/TP07_Polymorphisme/Q2_Moyenne/Moyenne1.java~
Normal file
@@ -0,0 +1,35 @@
|
||||
public class Moyenne1{
|
||||
double moyenne;
|
||||
int nbValeur;
|
||||
public Moyenne1(){
|
||||
this.nbValeur = 0;
|
||||
this.moyenne = 0;
|
||||
}
|
||||
public void add(byte valeur){
|
||||
this.nbValeur ++;
|
||||
this.moyenne = (this.moyenne*(this.nbValeur-1) + valeur)/(this.nbValeur);
|
||||
}
|
||||
public void add(short valeur){
|
||||
this.nbValeur ++;
|
||||
this.moyenne = (this.moyenne*(this.nbValeur-1) + valeur)/(this.nbValeur);
|
||||
}
|
||||
public void add(int valeur){
|
||||
this.nbValeur ++;
|
||||
this.moyenne = (this.moyenne*(this.nbValeur-1) + valeur)/(this.nbValeur);
|
||||
}
|
||||
public void add(long valeur){
|
||||
this.nbValeur ++;
|
||||
this.moyenne = (this.moyenne*(this.nbValeur-1) + valeur)/(this.nbValeur);
|
||||
}
|
||||
public void add(float valeur){
|
||||
this.nbValeur ++;
|
||||
this.moyenne = (this.moyenne*(this.nbValeur-1) + valeur)/(this.nbValeur);
|
||||
}
|
||||
public void add(double valeur){
|
||||
this.nbValeur ++;
|
||||
this.moyenne = (this.moyenne*(this.nbValeur-1) + valeur)/(this.nbValeur);
|
||||
}
|
||||
public double getAverage(){
|
||||
return this.moyenne;
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q2_Moyenne/Moyenne2.class
Normal file
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q2_Moyenne/Moyenne2.class
Normal file
Binary file not shown.
15
DEV/DEV2.1/TP07_Polymorphisme/Q2_Moyenne/Moyenne2.java
Normal file
15
DEV/DEV2.1/TP07_Polymorphisme/Q2_Moyenne/Moyenne2.java
Normal file
@@ -0,0 +1,15 @@
|
||||
public class Moyenne2{
|
||||
private double total;
|
||||
private int nbValeur;
|
||||
public Moyenne2(){
|
||||
this.nbValeur = 0;
|
||||
this.total = 0;
|
||||
}
|
||||
public void add(Number valeur){
|
||||
this.nbValeur ++;
|
||||
this.total += valeur.doubleValue();
|
||||
}
|
||||
public double getAverage(){
|
||||
return this.total/this.nbValeur;
|
||||
}
|
||||
}
|
||||
33
DEV/DEV2.1/TP07_Polymorphisme/Q2_Moyenne/Moyenne2.java~
Normal file
33
DEV/DEV2.1/TP07_Polymorphisme/Q2_Moyenne/Moyenne2.java~
Normal file
@@ -0,0 +1,33 @@
|
||||
public class absMoyenne2 extends Number{
|
||||
private double total;
|
||||
private int nbValeur;
|
||||
public Moyenne2(){
|
||||
this.nbValeur = 0;
|
||||
this.total = 0;
|
||||
}
|
||||
public void add(Number valeur){
|
||||
this.nbValeur ++;
|
||||
this.total += valeur.doubleValue();
|
||||
}
|
||||
public double getAverage(){
|
||||
return this.total/this.nbValeur;
|
||||
}
|
||||
/*@Override
|
||||
public double doubleValue() {
|
||||
return 1;
|
||||
}
|
||||
@Override
|
||||
public int intValue() {
|
||||
return (int) this.total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long longValue() {
|
||||
return (long) this.total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float floatValue() {
|
||||
return (float) this.total;
|
||||
}*/
|
||||
}
|
||||
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q2_Moyenne/Q2.class
Normal file
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q2_Moyenne/Q2.class
Normal file
Binary file not shown.
11
DEV/DEV2.1/TP07_Polymorphisme/Q2_Moyenne/Q2.java
Normal file
11
DEV/DEV2.1/TP07_Polymorphisme/Q2_Moyenne/Q2.java
Normal file
@@ -0,0 +1,11 @@
|
||||
public class Q2{
|
||||
public static void main(String[] args) {
|
||||
Moyenne2 test = new Moyenne2();
|
||||
test.add(10);
|
||||
test.add(3.333);
|
||||
test.add(3.333);
|
||||
test.add(3.333);
|
||||
test.add(3.333);
|
||||
System.out.println(test.getAverage());
|
||||
}
|
||||
}
|
||||
8
DEV/DEV2.1/TP07_Polymorphisme/Q2_Moyenne/Q2.java~
Normal file
8
DEV/DEV2.1/TP07_Polymorphisme/Q2_Moyenne/Q2.java~
Normal file
@@ -0,0 +1,8 @@
|
||||
public class Q2a{
|
||||
public static void main(String[] args) {
|
||||
Moyenne1 test = new Moyenne1();
|
||||
test.add(10);
|
||||
test.add(3.333);
|
||||
System.out.println(test.getAverage());
|
||||
}
|
||||
}
|
||||
0
DEV/DEV2.1/TP07_Polymorphisme/Q2a.java~
Normal file
0
DEV/DEV2.1/TP07_Polymorphisme/Q2a.java~
Normal file
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Etoile.class
Normal file
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Etoile.class
Normal file
Binary file not shown.
26
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Etoile.java
Normal file
26
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Etoile.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Graphe.class
Normal file
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Graphe.class
Normal file
Binary file not shown.
27
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Graphe.java
Normal file
27
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Graphe.java
Normal file
@@ -0,0 +1,27 @@
|
||||
import javax.swing.JComponent;
|
||||
import java.awt.*;
|
||||
|
||||
public class Graphe extends JComponent {
|
||||
public ProducteurDePoints graphe;
|
||||
|
||||
public Graphe(ProducteurDePoints graphe){
|
||||
this.graphe = graphe;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics pinceau) {
|
||||
Graphics secondPinceau = pinceau.create();
|
||||
if (this.isOpaque()) {
|
||||
secondPinceau.setColor(this.getBackground());
|
||||
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
secondPinceau.setColor(Color.BLACK);
|
||||
Point point1 = this.graphe.suivant();
|
||||
Point point2 = this.graphe.suivant();
|
||||
while (point2 != null){
|
||||
secondPinceau.drawLine(point1.x, point1.y, point2.x, point2.y);
|
||||
point1 = point2;
|
||||
point2 = this.graphe.suivant();
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/LigneAleatoire.class
Normal file
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/LigneAleatoire.class
Normal file
Binary file not shown.
@@ -0,0 +1,23 @@
|
||||
import java.awt.Point;
|
||||
import java.util.*;
|
||||
|
||||
public class LigneAleatoire implements ProducteurDePoints {
|
||||
private int numero;
|
||||
|
||||
public LigneAleatoire() {
|
||||
this.numero = 0;
|
||||
}
|
||||
|
||||
public Point suivant() {
|
||||
Point p = null;
|
||||
if (this.numero < 10) {
|
||||
p = new Point(((int) (Math.random()*200)+50),
|
||||
((int) (Math.random()*200)+50));
|
||||
this.numero++;
|
||||
} else {
|
||||
this.numero = 0;
|
||||
}
|
||||
System.out.println(p);
|
||||
return p;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
import java.awt.Point;
|
||||
|
||||
public interface ProducteurDePoints {
|
||||
Point suivant();
|
||||
}
|
||||
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Q3Main.class
Normal file
BIN
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Q3Main.class
Normal file
Binary file not shown.
18
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Q3Main.java
Normal file
18
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Q3Main.java
Normal file
@@ -0,0 +1,18 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Q3Main{
|
||||
public static void main(String[] args){
|
||||
JFrame fenetre = new JFrame();
|
||||
fenetre.setSize(500, 300);
|
||||
fenetre.setLocation(0, 0);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
ProducteurDePoints producteur = new LigneAleatoire();
|
||||
//ProducteurDePoints producteur = new Etoile();
|
||||
Graphe dessin = new Graphe(producteur);
|
||||
fenetre.add(dessin);
|
||||
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
||||
17
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Q3Main.java~
Normal file
17
DEV/DEV2.1/TP07_Polymorphisme/Q3_Polyligne/Q3Main.java~
Normal file
@@ -0,0 +1,17 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Q3Main{
|
||||
public static void main(String[] args){
|
||||
JFrame fenetre = new JFrame();
|
||||
fenetre.setSize(500, 300);
|
||||
fenetre.setLocation(0, 0);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
ProducteurDePoints producteurEtoile = new Etoile();
|
||||
Graphe dessinEtoile = new Graphe(producteurEtoile);
|
||||
fenetre.add(dessinEtoile);
|
||||
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
||||
0
DEV/DEV2.1/TP07_Polymorphisme/Test.java~
Normal file
0
DEV/DEV2.1/TP07_Polymorphisme/Test.java~
Normal file
4
DEV/DEV2.1/TP07_Polymorphisme/Vehicule.java~
Normal file
4
DEV/DEV2.1/TP07_Polymorphisme/Vehicule.java~
Normal file
@@ -0,0 +1,4 @@
|
||||
public interface Vehicule{
|
||||
int nbRoues();
|
||||
int sorte();
|
||||
}
|
||||
10
DEV/DEV2.1/TP07_Polymorphisme/Voiture.java~
Normal file
10
DEV/DEV2.1/TP07_Polymorphisme/Voiture.java~
Normal file
@@ -0,0 +1,10 @@
|
||||
public class Voiture implements Vehicule{
|
||||
@Override
|
||||
public int nbRoues(){
|
||||
return 4;
|
||||
}
|
||||
@Override
|
||||
public String sorte(){
|
||||
return "Vuitore";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user