Developpement/23DEV1.1/TPS2/TP01/Polymorphisme/Véhicule/TestVehicules.java

25 lines
615 B
Java
Raw Permalink Normal View History

2024-12-09 11:53:11 +01:00
import javax.swing.JOptionPane;
public class TestVehicules {
public static void main(String[] args) {
Vehicule v;
Object[] choix = {"Voiture", "Moto", "Camion"};
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 if (reponse == 1)
v = new Moto();
else
v = new Camion();
System.out.println("Une "+v.sorte()+" poss\u00E8de "+v.nbRoues()+" roues.");
}
}