Exerice 3: Ajout de constructeurs pour la partie 1.
This commit is contained in:
parent
04fa7e604a
commit
743a6c5c4d
3 changed files with 29 additions and 7 deletions
|
@ -3,14 +3,9 @@ import partie3.Voiture;
|
||||||
public class exercice3part1 {
|
public class exercice3part1 {
|
||||||
public static void main(String[] argv)
|
public static void main(String[] argv)
|
||||||
{
|
{
|
||||||
Voiture volkswagen = new Voiture();
|
Voiture volkswagen = new Voiture(30);
|
||||||
volkswagen.puissance = 30;
|
|
||||||
volkswagen.vitesse = 0;
|
|
||||||
volkswagen.estDemarre = false;
|
volkswagen.estDemarre = false;
|
||||||
Voiture renault = new Voiture();
|
Voiture renault = new Voiture(500,true);
|
||||||
renault.puissance = 500;
|
|
||||||
renault.vitesse = 200;
|
|
||||||
renault.estDemarre = true;
|
|
||||||
|
|
||||||
System.out.println(renault.puissance);
|
System.out.println(renault.puissance);
|
||||||
System.out.println(renault.vitesse);
|
System.out.println(renault.vitesse);
|
||||||
|
|
|
@ -4,4 +4,24 @@ public class Voiture {
|
||||||
public int puissance;
|
public int puissance;
|
||||||
public int vitesse;
|
public int vitesse;
|
||||||
public boolean estDemarre;
|
public boolean estDemarre;
|
||||||
|
|
||||||
|
public Voiture()
|
||||||
|
{
|
||||||
|
this.puissance = 10;
|
||||||
|
this.vitesse = 0;
|
||||||
|
this.estDemarre = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Voiture(int p)
|
||||||
|
{
|
||||||
|
this();
|
||||||
|
puissance = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Voiture(int p, boolean e)
|
||||||
|
{
|
||||||
|
this(p);
|
||||||
|
this.vitesse = (int)(p/3);
|
||||||
|
this.estDemarre = e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
7
src/partie3/Voiture2.java
Normal file
7
src/partie3/Voiture2.java
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package partie3;
|
||||||
|
|
||||||
|
public class Voiture2 {
|
||||||
|
int puissance;
|
||||||
|
int vitesse;
|
||||||
|
boolean estDemarre;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue