DEV_BUT1/DEV2.1/TP07/Test.java

41 lines
841 B
Java
Raw Normal View History

2023-04-04 14:03:16 +02:00
import javax.swing.JOptionPane;
interface Vehicule{
String sorte();
int nbroues();
}
class Voiture{
public int class nbroues(){
return 4;
}
public String class sorte(){
return "Voiture";
}
}
class Moto{
public int class nbroues(){
return 2;
}
public String class sorte(){
return "Moto";
}
}
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.");
}
}