This commit is contained in:
unknown
2022-01-14 06:54:18 +01:00
commit d9949b5cb0
288 changed files with 6425 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
public class Moto implements Vehicule{
int nbRoue;
String sorte;
public Moto(){
this.nbRoue=2;
this.sorte="Moto";
}
@Override
public int nbRoues(){
return this.nbRoue;
}
@Override
public String sorte(){
return this.sorte;
}
}

View File

@@ -0,0 +1,19 @@
public class Moyenne {
int numberOfNumber;
double total;
public Moyenne(){ //constructeur
}
double public getAverage(){
return this.numberOfNumber/this.total;
}
void public add(Number newNumber){
this.numberOfNumber++;
this.total+= newNumber.doubleValue();
}
}

View File

@@ -0,0 +1,22 @@
import javax.swing.JOptionPane;
public class Ex1 {
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,19 @@
public class Ex2
{
public static void main(String[] args)
{
short a = 5;
int b = 150;
long c = 200;
float d = 500.5f;
Moyenne moy = new Moyenne();
moy.add(a);
moy.add(b);
moy.add(c);
moy.add(d);
System.out.println("Moyenne: " + moy.getAverage());
}
}

View File

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

View File

@@ -0,0 +1,16 @@
public class Moyenne
{
int count = 0;
double all = 0;
public void add(Number nb)
{
count++;
all += nb.doubleValue();
}
public double getAverage()
{
return all/count;
}
}

View File

@@ -0,0 +1,19 @@
public class Ex2
{
public static void main(String[] args)
{
short a = 5;
int b = 150;
long c = 200;
float d = 500.5f;
Moyenne moy = new Moyenne();
moy.add(a);
moy.add(b);
moy.add(c);
moy.add(d);
System.out.println("Moyenne: " + moy.getAverage());
}
}

View File

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

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,5 @@
public interface Vehicule {
int nbRoues();
String sorte();
}

View File

@@ -0,0 +1,20 @@
public class Voiture implements Vehicule{
int nbRoue;
String sorte;
public Voiture(){
this.nbRoue=4;
this.sorte="Voiture";
}
@Override
public int nbRoues(){
return this.nbRoue;
}
@Override
public String sorte(){
return this.sorte;
}
}