diff --git a/java/src/vehicules/Moto.java b/java/src/vehicules/Moto.java new file mode 100644 index 0000000..0f2ad3c --- /dev/null +++ b/java/src/vehicules/Moto.java @@ -0,0 +1,19 @@ +package vehicules; + +public class Moto extends Vehicule { + private int puissance; + private int nbPneus = 2; + private Pneu pneu; + + public Moto(String couleur, String marque, String modele, int puissance) { + super(couleur, marque, modele); + this.puissance = puissance; + + if (marque.toLowerCase() == "yamaha") { + this.pneu = new Pneu(Type.VOITURE, "Dunlop"); + } + else { + this.pneu = new Pneu(Type.VOITURE, "Michelin"); + } + } +} diff --git a/java/src/vehicules/Pneu.java b/java/src/vehicules/Pneu.java new file mode 100644 index 0000000..f11c4dc --- /dev/null +++ b/java/src/vehicules/Pneu.java @@ -0,0 +1,17 @@ +package vehicules; + +enum Type { + MOTO, + VOITURE, +} + +public class Pneu { + private Type type; + private String marque; + private int largeur; + + public Pneu(Type type, String marque) { + this.type = type; + this.marque = marque; + } +} diff --git a/java/src/vehicules/Test.java b/java/src/vehicules/Test.java new file mode 100644 index 0000000..3437837 --- /dev/null +++ b/java/src/vehicules/Test.java @@ -0,0 +1,18 @@ +package vehicules; + +public class Test { + public static void main(String[] args) { + Voiture v1 = new Voiture("noire", "Citroën", "C4", "Routière"); + Voiture v2 = new Voiture("blanche", "Peugeot", "208 GTI", "Sportive"); + Voiture v3 = new Voiture("noire", "Renault", "Twingo", "Citadine"); + System.out.println(v1); + System.out.println(v2); + System.out.println(v3); + Moto m1 = new Moto("rouge", "Yamaha", "YBR", 125); + Moto m2 = new Moto("blanche", "Suzuki", "RM-Z250", 225); + Moto m3 = new Moto("noire", "Yamaha", "MT-03", 300); + System.out.println(m1); + System.out.println(m2); + System.out.println(m3); + } +} diff --git a/java/src/vehicules/Vehicule.java b/java/src/vehicules/Vehicule.java new file mode 100644 index 0000000..6304c59 --- /dev/null +++ b/java/src/vehicules/Vehicule.java @@ -0,0 +1,12 @@ +package vehicules; + +public class Vehicule { + private String couleur, marque, modele; + private int nbPneus; + + public Vehicule(String couleur, String marque, String modele) { + this.couleur = couleur; + this.marque = marque; + this.modele = modele; + } +} diff --git a/java/src/vehicules/Voiture.java b/java/src/vehicules/Voiture.java new file mode 100644 index 0000000..45184ba --- /dev/null +++ b/java/src/vehicules/Voiture.java @@ -0,0 +1,19 @@ +package vehicules; + +public class Voiture extends Vehicule { + private String categorie; + private int nbPneus = 4; + private Pneu pneu; + + public Voiture(String couleur, String marque, String modele, String categorie) { + super(couleur, marque, modele); + this.categorie = categorie; + + if (marque.toLowerCase() == "renault") { + this.pneu = new Pneu(Type.VOITURE, "Continental"); + } + else { + this.pneu = new Pneu(Type.VOITURE, "Michelin"); + } + } +}