update
This commit is contained in:
12
DEV.2.1/TP/TP7-Polymorphisme/1./Moto.java
Normal file
12
DEV.2.1/TP/TP7-Polymorphisme/1./Moto.java
Normal file
@@ -0,0 +1,12 @@
|
||||
public class Moto implements Vehicule {
|
||||
|
||||
@Override
|
||||
public int nbRoues() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String sorte() {
|
||||
return "Moto";
|
||||
}
|
||||
}
|
23
DEV.2.1/TP/TP7-Polymorphisme/1./Test.java
Normal file
23
DEV.2.1/TP/TP7-Polymorphisme/1./Test.java
Normal file
@@ -0,0 +1,23 @@
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
5
DEV.2.1/TP/TP7-Polymorphisme/1./Vehicule.java
Normal file
5
DEV.2.1/TP/TP7-Polymorphisme/1./Vehicule.java
Normal file
@@ -0,0 +1,5 @@
|
||||
public interface Vehicule {
|
||||
|
||||
public int nbRoues();
|
||||
public String sorte();
|
||||
}
|
12
DEV.2.1/TP/TP7-Polymorphisme/1./Voiture.java
Normal file
12
DEV.2.1/TP/TP7-Polymorphisme/1./Voiture.java
Normal file
@@ -0,0 +1,12 @@
|
||||
public class Voiture implements Vehicule {
|
||||
|
||||
@Override
|
||||
public String sorte() {
|
||||
return "Voiture";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nbRoues() {
|
||||
return 4;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user