Add vehicules

This commit is contained in:
flyingscorpio@clevo 2022-02-15 15:18:12 +01:00
parent c74a9b790b
commit a0aa1c2350
5 changed files with 85 additions and 0 deletions

View file

@ -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");
}
}
}

View file

@ -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;
}
}

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -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");
}
}
}