"depot M213"
This commit is contained in:
18
TD6/.vscode/launch.json
vendored
Executable file
18
TD6/.vscode/launch.json
vendored
Executable file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"type": "java",
|
||||
"name": "CodeLens (Launch) - TestPokemon",
|
||||
"request": "launch",
|
||||
"mainClass": "pkmA.TestPokemon",
|
||||
"projectName": "TD6"
|
||||
},
|
||||
{
|
||||
"type": "java",
|
||||
"name": "CodeLens (Launch) - GestionVehicule",
|
||||
"request": "launch",
|
||||
"mainClass": "vehicule.GestionVehicule",
|
||||
"projectName": "TD6"
|
||||
}
|
||||
]
|
||||
}
|
BIN
TD6/TD6.pdf
Executable file
BIN
TD6/TD6.pdf
Executable file
Binary file not shown.
5
TD6/src/pkmA/Attaque.java
Executable file
5
TD6/src/pkmA/Attaque.java
Executable file
@ -0,0 +1,5 @@
|
||||
package pkmA;
|
||||
|
||||
public interface Attaque {
|
||||
public void attaquer(Object adv);
|
||||
}
|
58
TD6/src/pkmA/Pokemon.java
Executable file
58
TD6/src/pkmA/Pokemon.java
Executable file
@ -0,0 +1,58 @@
|
||||
package pkmA;
|
||||
|
||||
public abstract class Pokemon{
|
||||
private String nom;
|
||||
private double taille;
|
||||
private double poids;
|
||||
private int pv;
|
||||
private int pc;
|
||||
Type type;
|
||||
|
||||
public Pokemon() {
|
||||
|
||||
}
|
||||
|
||||
public Pokemon(String nom, double taille, double poids, int pv, int pc, Type type) {
|
||||
if (type != Type.ELECTRIK && type != Type.EAU && type != Type.FEU && type != Type.PLANTE)
|
||||
throw new RuntimeException("Ce type : "+type.getDescription()+" n'existe pas");
|
||||
|
||||
try {
|
||||
this.nom = nom;
|
||||
this.taille = taille;
|
||||
this.poids = poids;
|
||||
this.pv = pv;
|
||||
this.pc = pc;
|
||||
this.type = type;
|
||||
} catch (Exception e) {
|
||||
e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public double getTaille() {
|
||||
return taille;
|
||||
}
|
||||
|
||||
public double getPoids() {
|
||||
return poids;
|
||||
}
|
||||
|
||||
public int getPv() {
|
||||
return pv;
|
||||
}
|
||||
|
||||
public int getPc() {
|
||||
return pc;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public abstract void changePv(int modif);
|
||||
|
||||
public abstract void attaquer(Pokemon adv);
|
||||
}
|
76
TD6/src/pkmA/PokemonEAU.java
Executable file
76
TD6/src/pkmA/PokemonEAU.java
Executable file
@ -0,0 +1,76 @@
|
||||
package pkmA;
|
||||
|
||||
public class PokemonEAU extends Pokemon{
|
||||
private String nom;
|
||||
private double taille; // en m
|
||||
private double poids; // en kg
|
||||
private int pv;
|
||||
private int pc;
|
||||
Type type;
|
||||
private int nb_nageoires;
|
||||
|
||||
public PokemonEAU() {
|
||||
type = Type.EAU;
|
||||
}
|
||||
|
||||
public PokemonEAU(String n, double t, double p, int v, int c, int g) {
|
||||
super(n, t, p, v, c, Type.EAU);
|
||||
this.nom = n;
|
||||
this.type = Type.EAU;
|
||||
nb_nageoires = g;
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public double getTaille() {
|
||||
return taille;
|
||||
}
|
||||
|
||||
public double getPoids() {
|
||||
return poids;
|
||||
}
|
||||
|
||||
public int getPv() {
|
||||
return pv;
|
||||
}
|
||||
|
||||
public int getPc() {
|
||||
return pc;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getNb_nageoires() {
|
||||
return nb_nageoires;
|
||||
}
|
||||
|
||||
public void changePv(int modif) {
|
||||
pv = Math.max(0, pv-modif);
|
||||
}
|
||||
|
||||
public double calculerVitesse() {
|
||||
return (this.poids*nb_nageoires)/25.0;
|
||||
}
|
||||
|
||||
public void attaquer(Pokemon adv) {
|
||||
if (adv.getType() == Type.EAU || adv.getType() == Type.PLANTE) {
|
||||
adv.changePv(Math.round(super.getPc()/2));
|
||||
System.out.println(""+this.getNom()+" inflige "+""+Math.round(super.getPc()/2)+" a "+adv.getNom());
|
||||
} else if (adv.getType() == Type.ELECTRIK) {
|
||||
adv.changePv(super.getPc());
|
||||
System.out.println(""+this.getNom()+" inflige "+""+super.getPc()+" a "+adv.getNom());
|
||||
} else {
|
||||
adv.changePv(2*super.getPc());
|
||||
System.out.println(""+this.getNom()+" inflige "+""+2*pc+" a "+adv.getNom());
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Pokemon "+super.getNom()+" de type "+type.getDescription()+" ("+super.getPoids()+" kg, "+super.getTaille()+" m, "+super.getPv()+" pts de vie, "+super.getPc()+" force de combat), "+nb_nageoires+" nageoires)";
|
||||
}
|
||||
|
||||
}
|
87
TD6/src/pkmA/PokemonELECTRIK.java
Executable file
87
TD6/src/pkmA/PokemonELECTRIK.java
Executable file
@ -0,0 +1,87 @@
|
||||
package pkmA;
|
||||
|
||||
public class PokemonELECTRIK extends Pokemon{
|
||||
private String nom;
|
||||
private double taille; // en m
|
||||
private double poids; // en kg
|
||||
private int pv;
|
||||
private int pc;
|
||||
Type type;
|
||||
private int nb_pattes;
|
||||
private int nb_ailes;
|
||||
private double intensite;
|
||||
|
||||
public PokemonELECTRIK() {
|
||||
type = Type.ELECTRIK;
|
||||
}
|
||||
|
||||
public PokemonELECTRIK(String n, double t, double p, int v, int c, int g, int a, double i) {
|
||||
super(n, t, p, v, c, Type.ELECTRIK);
|
||||
this.nom = n;
|
||||
this.type = Type.ELECTRIK;
|
||||
nb_pattes = g;
|
||||
nb_ailes = a;
|
||||
intensite = i;
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public double getTaille() {
|
||||
return taille;
|
||||
}
|
||||
|
||||
public double getPoids() {
|
||||
return poids;
|
||||
}
|
||||
|
||||
public int getPv() {
|
||||
return pv;
|
||||
}
|
||||
|
||||
public int getPc() {
|
||||
return pc;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getPattes() {
|
||||
return nb_pattes;
|
||||
}
|
||||
|
||||
public int getAiles() {
|
||||
return nb_ailes;
|
||||
}
|
||||
|
||||
public double getIntensite() {
|
||||
return intensite;
|
||||
}
|
||||
|
||||
public void changePv(int modif) {
|
||||
pv = Math.max(0, pv-modif);
|
||||
}
|
||||
|
||||
public double calculerVitesse() {
|
||||
return (nb_ailes+nb_pattes) * intensite * 0.05;
|
||||
}
|
||||
|
||||
public void attaquer(Pokemon adv) {
|
||||
if (adv.getType() == Type.ELECTRIK || adv.getType() == Type.PLANTE) {
|
||||
adv.changePv(Math.round(super.getPc()/2));
|
||||
System.out.println(""+this.getNom()+" inflige "+""+Math.round(super.getPc()/2)+" a "+adv.getNom());
|
||||
} else if (adv.getType() == Type.FEU) {
|
||||
adv.changePv(super.getPc());
|
||||
System.out.println(""+this.getNom()+" inflige "+""+super.getPc()+" a "+adv.getNom());
|
||||
} else {
|
||||
adv.changePv(2*super.getPc());
|
||||
System.out.println(""+this.getNom()+" inflige "+""+super.getPc()+" a "+adv.getNom());
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Pokemon "+super.getNom()+" de type "+type.getDescription()+" ("+super.getPoids()+" kg, "+super.getTaille()+" m, "+super.getPv()+" pts de vie, "+super.getPc()+" force de combat), "+nb_pattes+" pattes, "+nb_ailes+" ailes, "+intensite+" mA)";
|
||||
}
|
||||
}
|
76
TD6/src/pkmA/PokemonFEU.java
Executable file
76
TD6/src/pkmA/PokemonFEU.java
Executable file
@ -0,0 +1,76 @@
|
||||
package pkmA;
|
||||
|
||||
public class PokemonFEU extends Pokemon{
|
||||
private String nom;
|
||||
private double taille; // en m
|
||||
private double poids; // en kg
|
||||
private int pv;
|
||||
private int pc;
|
||||
Type type;
|
||||
private int nb_pattes;
|
||||
|
||||
public PokemonFEU() {
|
||||
type = Type.FEU;
|
||||
}
|
||||
|
||||
public PokemonFEU(String n, double t, double p, int v, int c, int g) {
|
||||
super(n, t, p, v, c, Type.FEU);
|
||||
this.nom = n;
|
||||
this.type = Type.FEU;
|
||||
nb_pattes = g;
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public double getTaille() {
|
||||
return taille;
|
||||
}
|
||||
|
||||
public double getPoids() {
|
||||
return poids;
|
||||
}
|
||||
|
||||
public int getPv() {
|
||||
return pv;
|
||||
}
|
||||
|
||||
public int getPc() {
|
||||
return pc;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getPattes() {
|
||||
return nb_pattes;
|
||||
}
|
||||
|
||||
public void changePv(int modif) {
|
||||
pv = Math.max(0, pv-modif);
|
||||
}
|
||||
|
||||
public double calculerVitesse() {
|
||||
return this.getPoids()*nb_pattes* 0.03;
|
||||
}
|
||||
|
||||
public void attaquer(Pokemon adv) {
|
||||
if (adv.getType() == Type.EAU || adv.getType() == Type.ELECTRIK) {
|
||||
adv.changePv(Math.round(super.getPc()/2));
|
||||
System.out.println(""+this.getNom()+" inflige "+""+Math.round(super.getPc()/2)+" a "+adv.getNom());
|
||||
} else if (adv.getType() == Type.FEU) {
|
||||
adv.changePv(super.getPc());
|
||||
System.out.println(""+this.getNom()+" inflige "+""+super.getPc()+" a "+adv.getNom());
|
||||
} else {
|
||||
adv.changePv(2*super.getPc());
|
||||
System.out.println(""+this.getNom()+" inflige "+""+2*super.getPc()+" a "+adv.getNom());
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Pokemon "+super.getNom()+" de type "+type.getDescription()+" ("+super.getPoids()+" kg, "+super.getTaille()+" m, "+super.getPv()+" pts de vie, "+super.getPc()+" force de combat), "+nb_pattes+" pattes)";
|
||||
}
|
||||
|
||||
}
|
70
TD6/src/pkmA/PokemonPLANTE.java
Executable file
70
TD6/src/pkmA/PokemonPLANTE.java
Executable file
@ -0,0 +1,70 @@
|
||||
package pkmA;
|
||||
|
||||
public class PokemonPLANTE extends Pokemon{
|
||||
private String nom;
|
||||
private double taille; // en m
|
||||
private double poids; // en kg
|
||||
private int pv;
|
||||
private int pc;
|
||||
Type type;
|
||||
|
||||
public PokemonPLANTE() {
|
||||
type = Type.PLANTE;
|
||||
}
|
||||
|
||||
public PokemonPLANTE(String n, double t, double p, int v, int c) {
|
||||
super(n, t, p, v, c, Type.PLANTE);
|
||||
this.nom = n;
|
||||
this.type = Type.PLANTE;
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public double getTaille() {
|
||||
return taille;
|
||||
}
|
||||
|
||||
public double getPoids() {
|
||||
return poids;
|
||||
}
|
||||
|
||||
public int getPv() {
|
||||
return pv;
|
||||
}
|
||||
|
||||
public int getPc() {
|
||||
return pc;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void changePv(int modif) {
|
||||
pv = Math.max(0, pv-modif);
|
||||
}
|
||||
|
||||
public double calculerVitesse() {
|
||||
return 10.0 / (this.getPoids()*this.getTaille());
|
||||
}
|
||||
|
||||
public void attaquer(Pokemon adv) {
|
||||
if (adv.getType() == Type.FEU || adv.getType() == Type.PLANTE) {
|
||||
adv.changePv(Math.round(super.getPc()/2));
|
||||
System.out.println(""+this.getNom()+" inflige "+""+Math.round(super.getPc()/2)+" a "+adv.getNom());
|
||||
} else if (adv.getType() == Type.EAU) {
|
||||
adv.changePv(super.getPc());
|
||||
System.out.println(""+this.getNom()+" inflige "+""+super.getPc()+" a "+adv.getNom());
|
||||
} else {
|
||||
adv.changePv(2*super.getPc());
|
||||
System.out.println(""+this.getNom()+" inflige "+""+2*super.getPc()+" a "+adv.getNom());
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Pokemon "+super.getNom()+" de type "+type.getDescription()+" ("+super.getPoids()+" kg, "+super.getTaille()+" m, "+super.getPv()+" pts de vie, "+super.getPc()+" force de combat),";
|
||||
}
|
||||
|
||||
}
|
23
TD6/src/pkmA/TestPokemon.java
Executable file
23
TD6/src/pkmA/TestPokemon.java
Executable file
@ -0,0 +1,23 @@
|
||||
package pkmA;
|
||||
|
||||
|
||||
public class TestPokemon {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Pokemon pikachu = new PokemonELECTRIK("Pikachu", 0.9, 5.3, 90, 50, 4, 0, 12);
|
||||
Pokemon aquali = new PokemonEAU("Aquali", 2.1, 56.3, 140, 90, 3);
|
||||
|
||||
pikachu.attaquer(aquali);
|
||||
assert aquali.getPv() == 40;
|
||||
|
||||
PokemonELECTRIK voltali = new PokemonELECTRIK("Voltali", 1.8, 47.3, 120, 130, 4, 0, 12);
|
||||
PokemonPLANTE phylali = new PokemonPLANTE("Phylali", 1.6, 28.5, 130, 70);
|
||||
Pokemon phyl = phylali;
|
||||
|
||||
phylali.attaquer(voltali);
|
||||
|
||||
aquali.attaquer(phyl);
|
||||
System.out.println(voltali.toString());
|
||||
}
|
||||
|
||||
}
|
11
TD6/src/pkmA/Type.java
Executable file
11
TD6/src/pkmA/Type.java
Executable file
@ -0,0 +1,11 @@
|
||||
package pkmA;
|
||||
|
||||
enum Type {
|
||||
EAU ("EAU"),
|
||||
ELECTRIK ("ELECTRIK"),
|
||||
FEU ("FEU"),
|
||||
PLANTE ("PLANTE");
|
||||
Type(String s){description = s;}
|
||||
private String description;
|
||||
public String getDescription() {return description;}
|
||||
}
|
87
TD6/src/pokemon/Pokemon.java
Executable file
87
TD6/src/pokemon/Pokemon.java
Executable file
@ -0,0 +1,87 @@
|
||||
package pokemon;
|
||||
|
||||
public abstract class Pokemon {
|
||||
|
||||
private String nom;
|
||||
private double taille; // en m
|
||||
private double poids; // en kg
|
||||
private int pv;
|
||||
private int pc;
|
||||
Type type;
|
||||
|
||||
//getters
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public double getTaille() {
|
||||
return taille;
|
||||
}
|
||||
|
||||
public double getPoids() {
|
||||
return poids;
|
||||
}
|
||||
|
||||
public int getPv() {
|
||||
return pv;
|
||||
}
|
||||
|
||||
public int getPc() {
|
||||
return pc;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
//setters
|
||||
public void setNom(String nom) {
|
||||
this.nom = nom;
|
||||
}
|
||||
|
||||
public void setTaille(double taille) {
|
||||
this.taille = taille;
|
||||
}
|
||||
|
||||
public void setPoids(double poids) {
|
||||
this.poids = poids;
|
||||
}
|
||||
|
||||
public void setPv(int pv) {
|
||||
this.pv = pv;
|
||||
}
|
||||
|
||||
public void setPc(int pc) {
|
||||
this.pc = pc;
|
||||
}
|
||||
|
||||
public void setType(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Pokemon() {
|
||||
nom = null;
|
||||
taille = 0.;
|
||||
poids = 0.;
|
||||
pv = 0;
|
||||
pc = 0;
|
||||
}
|
||||
|
||||
public Pokemon(String n, double t, double p, int pv, int pc) {
|
||||
this.nom = n;
|
||||
this.taille = t;
|
||||
this.poids = p;
|
||||
this.pv = pv;
|
||||
this.pc = pc;
|
||||
this.type = null;
|
||||
}
|
||||
|
||||
public double calculerVitesse() {
|
||||
return 0.;
|
||||
}
|
||||
|
||||
public double attack(Pokemon p2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
49
TD6/src/pokemon/PokemonEAU.java
Executable file
49
TD6/src/pokemon/PokemonEAU.java
Executable file
@ -0,0 +1,49 @@
|
||||
package pokemon;
|
||||
|
||||
public class PokemonEAU extends Pokemon{
|
||||
private int nb_nageoires;
|
||||
|
||||
public PokemonEAU(String n, double t, double p, int pv, int pc, int g) {
|
||||
super.setNom(n);
|
||||
super.setTaille(t);
|
||||
super.setPoids(p);
|
||||
super.setPv(pv);
|
||||
super.setPc(pc);
|
||||
this.type = Type.EAU;
|
||||
nb_nageoires = g;
|
||||
}
|
||||
public int getNb_nageoires() {
|
||||
return nb_nageoires;
|
||||
}
|
||||
|
||||
public void changePv(int modif) {
|
||||
this.setPv(Math.max(0, this.getPv() - modif));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double calculerVitesse() {
|
||||
return (this.getPoids() * nb_nageoires) / 25.0;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Statistiques du Pokemon \"" + this.getNom() + "\" de type " + type.getDescription() + " : (" + this.getPoids() + " kg, "
|
||||
+ this.getTaille() + " m, " + this.getPv() + " pts de vie, " + this.getPc() + " force de combat, " + nb_nageoires + " nageoires)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public double attack(Pokemon p2) {
|
||||
if(p2.type == Type.ELECTRIK) {
|
||||
p2.setPv(p2.getPv()-this.getPc());
|
||||
}
|
||||
else if(p2.type == Type.FEU) {
|
||||
p2.setPv((p2.getPv()-this.getPc()*2));
|
||||
}
|
||||
else {
|
||||
p2.setPv((p2.getPv()-this.getPc()/2));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
58
TD6/src/pokemon/PokemonELECTRIK.java
Executable file
58
TD6/src/pokemon/PokemonELECTRIK.java
Executable file
@ -0,0 +1,58 @@
|
||||
package pokemon;
|
||||
|
||||
public class PokemonELECTRIK extends Pokemon {
|
||||
private int nb_pattes;
|
||||
private int nb_ailes;
|
||||
private double intensite;
|
||||
|
||||
public PokemonELECTRIK(String n, double t, double p, int pv, int pc, int g, int a, double i) {
|
||||
super.setNom(n);
|
||||
super.setTaille(t);
|
||||
super.setPoids(p);
|
||||
super.setPv(pv);
|
||||
super.setPc(pc);
|
||||
this.type = Type.ELECTRIK;
|
||||
nb_pattes = g;
|
||||
nb_ailes = a;
|
||||
intensite = i;
|
||||
}
|
||||
|
||||
public int getPattes() {
|
||||
return nb_pattes;
|
||||
}
|
||||
|
||||
public int getAiles() {
|
||||
return nb_ailes;
|
||||
}
|
||||
|
||||
public double getIntensite() {
|
||||
return intensite;
|
||||
}
|
||||
|
||||
public void changePv(int modif) {
|
||||
this.setPv(Math.max(0, this.getPv() - modif));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double calculerVitesse() {
|
||||
return (nb_ailes + nb_pattes) * intensite * 0.05;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Statistiques du Pokemon \"" + this.getNom() + "\" de type " + type.getDescription() + " : ("
|
||||
+ this.getPoids() + " kg, " + this.getTaille() + " m, " + this.getPv() + " pts de vie, " + this.getPc()
|
||||
+ " force de combat, " + nb_pattes + " pattes, " + nb_ailes + " ailes, " + intensite + " mA)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public double attack(Pokemon p2) {
|
||||
if (p2.type == Type.FEU) {
|
||||
p2.setPv(p2.getPv() - this.getPc());
|
||||
} else if (p2.type == Type.EAU) {
|
||||
p2.setPv((p2.getPv() - this.getPc() * 2));
|
||||
} else {
|
||||
p2.setPv((p2.getPv() - this.getPc() / 2));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
49
TD6/src/pokemon/PokemonFEU.java
Executable file
49
TD6/src/pokemon/PokemonFEU.java
Executable file
@ -0,0 +1,49 @@
|
||||
package pokemon;
|
||||
|
||||
public class PokemonFEU extends Pokemon {
|
||||
private int nb_pattes;
|
||||
|
||||
public PokemonFEU(String n, double t, double p, int pv, int pc, int g) {
|
||||
super.setNom(n);
|
||||
super.setTaille(t);
|
||||
super.setPoids(p);
|
||||
super.setPv(pv);
|
||||
super.setPc(pc);
|
||||
this.type = Type.FEU;
|
||||
nb_pattes = g;
|
||||
}
|
||||
|
||||
public int getPattes() {
|
||||
return nb_pattes;
|
||||
}
|
||||
|
||||
public void changePv(int modif) {
|
||||
this.setPv(Math.max(0, this.getPv() - modif));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double calculerVitesse() {
|
||||
return this.getPoids() * nb_pattes * 0.03;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Statistiques du Pokemon \"" + this.getNom() + "\" de type " + type.getDescription() + " : (" + this.getPoids() + " kg, "
|
||||
+ this.getTaille() + " m, " + this.getPv() + " pts de vie, " + this.getPc() + " force de combat, "
|
||||
+ nb_pattes + " pattes)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public double attack(Pokemon p2) {
|
||||
if(p2.type == Type.FEU) {
|
||||
p2.setPv(p2.getPv()-this.getPc());
|
||||
}
|
||||
else if(p2.type == Type.PLANTE) {
|
||||
p2.setPv((p2.getPv()-this.getPc()*2));
|
||||
}
|
||||
else {
|
||||
p2.setPv((p2.getPv()-this.getPc()/2));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
42
TD6/src/pokemon/PokemonPLANTE.java
Executable file
42
TD6/src/pokemon/PokemonPLANTE.java
Executable file
@ -0,0 +1,42 @@
|
||||
package pokemon;
|
||||
|
||||
public class PokemonPLANTE extends Pokemon{
|
||||
|
||||
public PokemonPLANTE(String n, double t, double p, int pv, int pc) {
|
||||
super.setNom(n);
|
||||
super.setTaille(t);
|
||||
super.setPoids(p);
|
||||
super.setPv(pv);
|
||||
super.setPc(pc);
|
||||
this.type = Type.PLANTE;
|
||||
}
|
||||
|
||||
public void changePv(int modif) {
|
||||
this.setPv(Math.max(0, this.getPv() - modif));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double calculerVitesse() {
|
||||
return 10.0 / (this.getPoids() * this.getTaille());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Statistiques du Pokemon \"" + this.getNom() + "\" de type " + type.getDescription() + " : (" + this.getPoids() + " kg, "
|
||||
+ this.getTaille() + " m, " + this.getPv() + " pts de vie, " + this.getPc() + " force de combat)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public double attack(Pokemon p2) {
|
||||
if(p2.type == Type.EAU) {
|
||||
p2.setPv(p2.getPv()-this.getPc());
|
||||
}
|
||||
else if(p2.type == Type.ELECTRIK) {
|
||||
p2.setPv((p2.getPv()-this.getPc()*2));
|
||||
}
|
||||
else {
|
||||
p2.setPv((p2.getPv()-this.getPc()/2));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
56
TD6/src/pokemon/TestPokemon.java
Executable file
56
TD6/src/pokemon/TestPokemon.java
Executable file
@ -0,0 +1,56 @@
|
||||
package pokemon;
|
||||
|
||||
public class TestPokemon {
|
||||
public static void main(String[] args) {
|
||||
|
||||
Pokemon tabPKM[] = new Pokemon[8];
|
||||
|
||||
//fire
|
||||
PokemonFEU Infernape = new PokemonFEU("Infernape", 1.2, 55., 356, 45, 4);
|
||||
PokemonFEU Ninetales = new PokemonFEU("Ninetales", 1.1, 19.9, 350, 26, 4);
|
||||
|
||||
//Electric
|
||||
PokemonELECTRIK Ampharos = new PokemonELECTRIK("Ampharos", 1.4, 61.5, 384, 32, 2, 0, 95);
|
||||
PokemonELECTRIK RaichuA = new PokemonELECTRIK("Raichu Alolan Form", .7, 21., 324, 37, 2, 0, 105);
|
||||
|
||||
//water
|
||||
PokemonEAU Ludicolo = new PokemonEAU("Ludicolo", 1.5, 55., 364, 45, 2);
|
||||
PokemonEAU Froakie = new PokemonEAU("Froakie", .3, 7., 286, 20, 2);
|
||||
|
||||
//grass
|
||||
PokemonPLANTE Roselia = new PokemonPLANTE("Roselia", .3, 2., 304, 14);
|
||||
PokemonPLANTE Torterra = new PokemonPLANTE("Torterra", 2.2, 310., 394, 44);
|
||||
|
||||
tabPKM[0] = Infernape;
|
||||
tabPKM[1] = Ninetales;
|
||||
tabPKM[2] = Ampharos;
|
||||
tabPKM[3] = RaichuA;
|
||||
tabPKM[4] = Ludicolo;
|
||||
tabPKM[5] = Froakie;
|
||||
tabPKM[6] = Roselia;
|
||||
tabPKM[7] = Torterra;
|
||||
|
||||
for (int i = 0; i < tabPKM.length; i++) {
|
||||
System.out.println(tabPKM[i].toString());
|
||||
}
|
||||
|
||||
Infernape.attack(Ludicolo);
|
||||
Ludicolo.attack(Froakie);
|
||||
Froakie.attack(Infernape);
|
||||
Torterra.attack(Roselia);
|
||||
Roselia.attack(RaichuA);
|
||||
RaichuA.attack(Ninetales);
|
||||
Ninetales.attack(Roselia);
|
||||
Torterra.attack(Roselia);
|
||||
|
||||
System.out.println("=========================================================================");
|
||||
|
||||
for (int i = 0; i < tabPKM.length; i++) {
|
||||
System.out.println(tabPKM[i].toString());
|
||||
}
|
||||
|
||||
|
||||
System.out.println("Hello Pokeworld !");
|
||||
|
||||
}
|
||||
}
|
19
TD6/src/pokemon/Type.java
Executable file
19
TD6/src/pokemon/Type.java
Executable file
@ -0,0 +1,19 @@
|
||||
package pokemon;
|
||||
|
||||
enum Type {
|
||||
|
||||
EAU("EAU"),
|
||||
ELECTRIK("ELECTRIK"),
|
||||
FEU("FEU"),
|
||||
PLANTE("PLANTE");
|
||||
|
||||
Type(String s) {
|
||||
description = s;
|
||||
}
|
||||
|
||||
private String description;
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
}
|
37
TD6/src/vehicule/Avion.java
Executable file
37
TD6/src/vehicule/Avion.java
Executable file
@ -0,0 +1,37 @@
|
||||
package vehicule;
|
||||
|
||||
public class Avion extends Vehicule {
|
||||
protected String moteur;
|
||||
protected int heuresVol;
|
||||
|
||||
public Avion() {
|
||||
moteur = "Moteur";
|
||||
heuresVol = 0;
|
||||
}
|
||||
|
||||
public Avion(String marque, int date, double prixac, String moteur, int heures) {
|
||||
this.moteur = moteur;
|
||||
heuresVol = heures;
|
||||
this.marque = marque;
|
||||
dateAchat = date;
|
||||
prixAchat = prixac;
|
||||
prixCourant = 0;
|
||||
}
|
||||
|
||||
public void calculePrix(int annee) {
|
||||
double pourcentage;
|
||||
if (moteur == "hélice") {
|
||||
pourcentage = 10*Math.floor(this.heuresVol/100);
|
||||
} else {
|
||||
pourcentage = 10* Math.floor(this.heuresVol/1000);
|
||||
}
|
||||
super.prixCourant = super.prixAchat - ((super.prixAchat/100) * pourcentage);
|
||||
if (super.prixCourant < 0) {
|
||||
super.prixCourant = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void affiche() {
|
||||
System.out.println(""+this.marque+" "+this.dateAchat+" "+this.prixAchat+" "+prixCourant+" "+this.moteur+" "+this.heuresVol);
|
||||
}
|
||||
}
|
29
TD6/src/vehicule/GestionVehicule.java
Executable file
29
TD6/src/vehicule/GestionVehicule.java
Executable file
@ -0,0 +1,29 @@
|
||||
package vehicule;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
public class GestionVehicule {
|
||||
private static int ANNEE_ACTUELLE = Calendar.getInstance().get(Calendar.YEAR);
|
||||
|
||||
public static void main(String[] args) {
|
||||
Voiture[] garage = new Voiture[3];
|
||||
Avion[] hangar = new Avion[2];
|
||||
|
||||
garage[0] = new Voiture("Peugeot", 2005, 13400.00, 1.4, 5, 4.0, 12000);
|
||||
garage[1] = new Voiture("Porsche", 2010, 160000.00, 3.6, 2, 25.0, 8320);
|
||||
garage[2] = new Voiture("Fiat", 1999, 8400.00, 1.2, 3, 5.0, 125000);
|
||||
|
||||
hangar[0] = new Avion("Cessna", 1979, 204739.90, "HELICES", 250);
|
||||
hangar[1] = new Avion("Gulfstream", 1993, 4321098.00, "REACTION", 1300);
|
||||
|
||||
for (int i = 0; i < garage.length; i++) {
|
||||
garage[i].calculePrix(ANNEE_ACTUELLE);
|
||||
garage[i].affiche();
|
||||
}
|
||||
|
||||
for (int i = 0; i < hangar.length; i++) {
|
||||
hangar[i].calculePrix(ANNEE_ACTUELLE);
|
||||
hangar[i].affiche();
|
||||
}
|
||||
}
|
||||
}
|
32
TD6/src/vehicule/Vehicule.java
Executable file
32
TD6/src/vehicule/Vehicule.java
Executable file
@ -0,0 +1,32 @@
|
||||
package vehicule;
|
||||
|
||||
public abstract class Vehicule {
|
||||
protected String marque;
|
||||
protected int dateAchat;
|
||||
protected double prixAchat;
|
||||
protected double prixCourant;
|
||||
|
||||
public Vehicule() {
|
||||
marque = "";
|
||||
dateAchat = 0;
|
||||
prixAchat = 0;
|
||||
prixCourant = 0;
|
||||
}
|
||||
|
||||
public Vehicule(String s, int d, double pA) {
|
||||
this.marque = s;
|
||||
dateAchat = d;
|
||||
prixAchat = pA;
|
||||
prixCourant = 0;
|
||||
}
|
||||
|
||||
public void calculPrix(int y) {
|
||||
int previousY = this.dateAchat - y;
|
||||
this.prixCourant = this.prixAchat - ((this.prixAchat/100) * previousY);
|
||||
}
|
||||
|
||||
public void affiche() {
|
||||
System.out.println(""+this.marque+" "+this.dateAchat+" "+this.prixAchat+" "+prixCourant);
|
||||
}
|
||||
|
||||
}
|
58
TD6/src/vehicule/Voiture.java
Executable file
58
TD6/src/vehicule/Voiture.java
Executable file
@ -0,0 +1,58 @@
|
||||
package vehicule;
|
||||
|
||||
public class Voiture extends Vehicule {
|
||||
protected double cylindree;
|
||||
protected int nbPorte;
|
||||
protected double puissance;
|
||||
protected double kilometrage;
|
||||
|
||||
public Voiture() {
|
||||
cylindree = 0;
|
||||
nbPorte = 0;
|
||||
puissance = 0;
|
||||
kilometrage = 0;
|
||||
}
|
||||
|
||||
public Voiture(String marque, int date, double prixac, double cyl, int nbP, double pui, double kilo) {
|
||||
cylindree = cyl;
|
||||
nbPorte = nbP;
|
||||
puissance = pui;
|
||||
kilometrage = kilo;
|
||||
this.marque = marque;
|
||||
dateAchat = date;
|
||||
prixAchat = prixac;
|
||||
prixCourant = 0;
|
||||
}
|
||||
|
||||
|
||||
public void calculePrix(int annee) {
|
||||
int anneesPass = (annee - this.dateAchat)*2;
|
||||
double pourcentagekm = Math.floor(this.kilometrage/10000);
|
||||
boolean malus = false;
|
||||
boolean bonus = false;
|
||||
if (this.marque == "fiat" || this.marque == "renaud") {
|
||||
malus = true;
|
||||
} else if (this.marque == "ferrari" || this.marque == "mclaren") {
|
||||
bonus = true;
|
||||
}
|
||||
|
||||
this.prixCourant = this.prixAchat - ((this.prixAchat/100) * anneesPass);
|
||||
this.prixCourant -= ((this.prixAchat/100)*(pourcentagekm*5));
|
||||
if (malus)
|
||||
this.prixCourant -= (this.prixAchat/100)*10;
|
||||
|
||||
if (bonus)
|
||||
this.prixCourant += (this.prixAchat/100)*20;
|
||||
|
||||
if (this.prixCourant < 0) {
|
||||
this.prixCourant = 0;
|
||||
} else if (this.prixCourant > this.prixAchat) {
|
||||
this.prixCourant = this.prixAchat;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void affiche() {
|
||||
System.out.println("Marque : "+this.marque+" Date: "+this.dateAchat+" Prix d'achat "+this.prixAchat+" Prix Courant :"+this.prixCourant+" Cylindree "+this.cylindree+" Nb Portes "+this.nbPorte+" Puissance "+this.puissance+" Kilometrage "+this.kilometrage);
|
||||
}
|
||||
}
|
34
TD6/src/vehiculev2/Camion.java
Executable file
34
TD6/src/vehiculev2/Camion.java
Executable file
@ -0,0 +1,34 @@
|
||||
package vehiculev2;
|
||||
|
||||
public class Camion extends VehiculeAMoteur {
|
||||
|
||||
private double Volume;
|
||||
|
||||
|
||||
/*==========================================================Getter & Setters====================================================================*/
|
||||
/**
|
||||
* @return the nombrePlace
|
||||
*/
|
||||
public double getVolume() {
|
||||
return Volume;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nombrePlace the nombrePlace to set
|
||||
*/
|
||||
public void setVolume(int Volume) {
|
||||
this.Volume = Volume;
|
||||
}
|
||||
/*==========================================================Getter & Setters====================================================================*/
|
||||
|
||||
public Camion(double v, double c) {
|
||||
super(c);
|
||||
this.Volume = v;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + " et un réservoir de" + this.Volume + "m^3.";
|
||||
}
|
||||
|
||||
|
||||
}
|
18
TD6/src/vehiculev2/GestionVehicule.java
Executable file
18
TD6/src/vehiculev2/GestionVehicule.java
Executable file
@ -0,0 +1,18 @@
|
||||
package vehiculev2;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
public class GestionVehicule {
|
||||
|
||||
public static void main (String [] args) {
|
||||
Vehicule v1 = new Velo (17); // nb vitesses
|
||||
Vehicule v2 = new Voiture (40.5, 5); // capacité réservoir, nb Places
|
||||
Vehicule v3 = new Camion (100.0, 100.0); // capacité réservoir, volume
|
||||
System.out.println ("Vehicules : "+"\n" +v1 +"\n" +v2 +"\n" +v3 +"\n");
|
||||
/*
|
||||
* v2.approvisionner (35.0) ; // litres d’essence v3.approvisionner (70.0);
|
||||
* v1.transporter ("Dijon ", "Valence ") ; v2.transporter (5, 300) ;
|
||||
* v3.transporter (" des tuiles", 1000) ; }
|
||||
*/
|
||||
}
|
||||
}
|
72
TD6/src/vehiculev2/Vehicule.java
Executable file
72
TD6/src/vehiculev2/Vehicule.java
Executable file
@ -0,0 +1,72 @@
|
||||
package vehiculev2;
|
||||
|
||||
public abstract class Vehicule {
|
||||
|
||||
private static int compteur = 0;
|
||||
private int id;
|
||||
private double distance;
|
||||
|
||||
/*==========================================================Getter & Setters====================================================================*/
|
||||
|
||||
/**
|
||||
* @return the compteur
|
||||
*/
|
||||
public static int getCompteur() {
|
||||
return compteur;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the distance
|
||||
*/
|
||||
public double getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param distance the distance to set
|
||||
*/
|
||||
public void setDistance(int distance) {
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param compteur the compteur to set
|
||||
*/
|
||||
public static void setCompteur(int compteur) {
|
||||
Vehicule.compteur = compteur;
|
||||
}
|
||||
|
||||
/*==============================================================================================================================================*/
|
||||
|
||||
public Vehicule() {
|
||||
this.id = compteur;
|
||||
compteur++;
|
||||
distance = 0.;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Le véhicule Numéro " + id + " a parcourru " + distance;
|
||||
}
|
||||
|
||||
void rouler(double d) {
|
||||
this.distance = d;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
74
TD6/src/vehiculev2/VehiculeAMoteur.java
Executable file
74
TD6/src/vehiculev2/VehiculeAMoteur.java
Executable file
@ -0,0 +1,74 @@
|
||||
package vehiculev2;
|
||||
|
||||
public abstract class VehiculeAMoteur extends Vehicule {
|
||||
|
||||
private double capacite;
|
||||
private double niveau;
|
||||
|
||||
/*==========================================================Getter & Setters====================================================================*/
|
||||
|
||||
/**
|
||||
* @return the capacite
|
||||
*/
|
||||
public double getCapacite() {
|
||||
return capacite;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the niveau
|
||||
*/
|
||||
public double getNiveau() {
|
||||
return niveau;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param niveau the niveau to set
|
||||
*/
|
||||
public void setNiveau(int niveau) {
|
||||
this.niveau = niveau;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param capacite the capacite to set
|
||||
*/
|
||||
public void setCapacite(int capacite) {
|
||||
this.capacite = capacite;
|
||||
}
|
||||
|
||||
/*==========================================================Getter & Setters====================================================================*/
|
||||
|
||||
public VehiculeAMoteur() {
|
||||
this.capacite = 0.;
|
||||
}
|
||||
|
||||
public VehiculeAMoteur(double c) {
|
||||
super();
|
||||
this.capacite = c;
|
||||
this.niveau = 0.;
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ", possède un moteur de " + this.capacite + " L";
|
||||
}
|
||||
|
||||
public boolean enPanne() {
|
||||
if(this.niveau <= 0. )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void approvisionner(double nbL) {
|
||||
if (nbL >= this.capacite) {
|
||||
nbL = this.capacite;
|
||||
}
|
||||
this.niveau = nbL;
|
||||
}
|
||||
|
||||
|
||||
}
|
20
TD6/src/vehiculev2/VehiculeSansMoteur.java
Executable file
20
TD6/src/vehiculev2/VehiculeSansMoteur.java
Executable file
@ -0,0 +1,20 @@
|
||||
package vehiculev2;
|
||||
|
||||
public abstract class VehiculeSansMoteur extends Vehicule {
|
||||
|
||||
public VehiculeSansMoteur() {
|
||||
super();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
39
TD6/src/vehiculev2/Velo.java
Executable file
39
TD6/src/vehiculev2/Velo.java
Executable file
@ -0,0 +1,39 @@
|
||||
package vehiculev2;
|
||||
|
||||
public class Velo extends VehiculeSansMoteur{
|
||||
|
||||
private int nombreVitesse;
|
||||
|
||||
|
||||
/*==========================================================Getter & Setters====================================================================*/
|
||||
/**
|
||||
* @return the nombreVitesse
|
||||
*/
|
||||
public int getNombreVitesse() {
|
||||
return nombreVitesse;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nombreVitesse the nombreVitesse to set
|
||||
*/
|
||||
public void setNombreVitesse(int nombreVitesse) {
|
||||
this.nombreVitesse = nombreVitesse;
|
||||
}
|
||||
/*==========================================================Getter & Setters====================================================================*/
|
||||
|
||||
public Velo(int nb) {
|
||||
super();
|
||||
this.nombreVitesse = nb;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + " et possède " + this.nombreVitesse + " vitesses sur son vélo.";
|
||||
}
|
||||
|
||||
|
||||
|
||||
String transporter (String depart, String arrivee) {
|
||||
return "Le vélo n°" + (super.getId()) + "a roulé de " + depart + " à " + arrivee;
|
||||
}
|
||||
|
||||
}
|
32
TD6/src/vehiculev2/Voiture.java
Executable file
32
TD6/src/vehiculev2/Voiture.java
Executable file
@ -0,0 +1,32 @@
|
||||
package vehiculev2;
|
||||
|
||||
public class Voiture extends VehiculeAMoteur {
|
||||
|
||||
private int nombrePlace;
|
||||
|
||||
|
||||
/*==========================================================Getter & Setters====================================================================*/
|
||||
/**
|
||||
* @return the nombrePlace
|
||||
*/
|
||||
public int getNombrePlace() {
|
||||
return nombrePlace;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nombrePlace the nombrePlace to set
|
||||
*/
|
||||
public void setNombrePlace(int nombrePlace) {
|
||||
this.nombrePlace = nombrePlace;
|
||||
}
|
||||
/*==========================================================Getter & Setters====================================================================*/
|
||||
|
||||
public Voiture(double c, int nb) {
|
||||
super(c);
|
||||
this.nombrePlace = nb;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + " et " + this.nombrePlace + "places dans la voiture.";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user