This commit is contained in:
2023-10-23 13:23:36 +02:00
parent 667dae6f1a
commit 322b22f9bf
5711 changed files with 72953 additions and 0 deletions

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

Binary file not shown.

View File

@@ -0,0 +1,10 @@
public class Moto implements Vehicule{
@Override
public int nbRoues(){
return 1;
}
@Override
public String sorte(){
return "bcaene";
}
}

Binary file not shown.

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

View File

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

View File

@@ -0,0 +1,10 @@
public class Voiture implements Vehicule{
@Override
public int nbRoues(){
return 4;
}
@Override
public String sorte(){
return "vuitore";
}
}

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

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

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

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

Binary file not shown.

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

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

View File

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

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

View File

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

View File

@@ -0,0 +1,5 @@
import java.awt.Point;
public interface ProducteurDePoints {
Point suivant();
}

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

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

View File

View File

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

View File

@@ -0,0 +1,10 @@
public class Voiture implements Vehicule{
@Override
public int nbRoues(){
return 4;
}
@Override
public String sorte(){
return "Vuitore";
}
}