fin
This commit is contained in:
BIN
DEV2.1/Polymophisme/ex1/Moto.class
Normal file
BIN
DEV2.1/Polymophisme/ex1/Moto.class
Normal file
Binary file not shown.
18
DEV2.1/Polymophisme/ex1/Moto.java
Normal file
18
DEV2.1/Polymophisme/ex1/Moto.java
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
public class Moto implements Vehicule{
|
||||
private String type;
|
||||
private int roues;
|
||||
|
||||
public Moto(){
|
||||
this.type = "moto";
|
||||
this.roues = 2;
|
||||
}
|
||||
|
||||
public int nbRoues(){
|
||||
return this.roues;
|
||||
}
|
||||
|
||||
public String sorte(){
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
BIN
DEV2.1/Polymophisme/ex1/Test.class
Normal file
BIN
DEV2.1/Polymophisme/ex1/Test.class
Normal file
Binary file not shown.
22
DEV2.1/Polymophisme/ex1/Test.java
Normal file
22
DEV2.1/Polymophisme/ex1/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/Polymophisme/ex1/Vehicule.class
Normal file
BIN
DEV2.1/Polymophisme/ex1/Vehicule.class
Normal file
Binary file not shown.
5
DEV2.1/Polymophisme/ex1/Vehicule.java
Normal file
5
DEV2.1/Polymophisme/ex1/Vehicule.java
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
public interface Vehicule {
|
||||
String sorte();
|
||||
int nbRoues();
|
||||
}
|
||||
BIN
DEV2.1/Polymophisme/ex1/Voiture.class
Normal file
BIN
DEV2.1/Polymophisme/ex1/Voiture.class
Normal file
Binary file not shown.
19
DEV2.1/Polymophisme/ex1/Voiture.java
Normal file
19
DEV2.1/Polymophisme/ex1/Voiture.java
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
public class Voiture implements Vehicule{
|
||||
private String type;
|
||||
private int roues;
|
||||
|
||||
public Voiture(){
|
||||
this.type = "voiture";
|
||||
this.roues = 4;
|
||||
}
|
||||
|
||||
public int nbRoues(){
|
||||
return this.roues;
|
||||
}
|
||||
|
||||
public String sorte(){
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user