"depot M213"

This commit is contained in:
JunkJumper
2020-05-03 14:24:13 +02:00
parent 1408744dbb
commit e5983242c6
136 changed files with 161184 additions and 0 deletions

18
TD8/.vscode/launch.json vendored Executable file
View File

@ -0,0 +1,18 @@
{
"configurations": [
{
"type": "java",
"name": "CodeLens (Launch) - TestPokemon",
"request": "launch",
"mainClass": "pokemon.TestPokemon",
"projectName": "TD8"
},
{
"type": "java",
"name": "CodeLens (Launch) - TestExercices",
"request": "launch",
"mainClass": "services.TestExercices",
"projectName": "TD8"
}
]
}

BIN
TD8/TD8.pdf Executable file

Binary file not shown.

45
TD8/src/parking/Parking.java Executable file
View File

@ -0,0 +1,45 @@
package parking;
import vehicule.Voiture;
import java.util.HashMap;
public class Parking {
int taille;
HashMap<Integer, Voiture> parking = new HashMap<Integer, Voiture>();
public Parking(int nbplace, HashMap<Integer, Voiture> park) {
taille = nbplace;
parking = park;
}
public void garer(Voiture v, int place) throws IndexOutOfBoundsException, IllegalStateException{
if(place>taille || place<0)
throw new IndexOutOfBoundsException("Place inexistante");
if(parking.get(place)==null) {
parking.put(place, v);
}else {
throw new IllegalStateException("Place occup<75>");
}
}
public Voiture liberer(int place) throws IndexOutOfBoundsException{
Voiture voit = parking.get(place);
parking.remove(place);
return voit;
}
public int chercher(Voiture v) throws IllegalStateException {
for (int i = 0; i < parking.size(); i++) {
if(parking.get(i).equals(v)) {
return i;
}else {
throw new IllegalStateException("Place inexistante");
}
}
System.out.println("Voiture non pr<70>sente");
return 0;
}
public String toString() {
for (int i = 0; i < parking.size()-1; i++) {
System.out.println("Place : " + i + " Voiture " + parking.get(i));
}
return "Place : " + taille + " Voiture" + parking.get(taille);
}
}

View File

@ -0,0 +1,27 @@
package parking;
import java.util.HashMap;
import vehicule.Voiture;
public class ParkingTest {
public static void main(String[] args) {
HashMap<Integer, Voiture> carpark = new HashMap<Integer, Voiture>();
Voiture v1 = new Voiture("Peugeot", 2005, 13400.00, 1.4, 5, 4.0, 12000);
Voiture v2 = new Voiture("Porsche", 2010, 160000.00, 3.6, 2, 25.0, 8320);
Voiture v3 = new Voiture("Fiat", 1999, 8400.00, 1.2, 3, 5.0, 125000);
Parking P1 = new Parking(50, carpark);
try {
P1.garer(v1, 0);
P1.garer(v2, 1);
P1.garer(v3, 2);
System.out.println("Place v2 : " + P1.chercher(v2));
P1.liberer(1);
System.out.println(P1.chercher(v2));
}catch(IndexOutOfBoundsException e) {
System.out.println(e.getMessage());
}catch(IllegalStateException e) {
System.out.println(e.getMessage());
}
P1.toString();
}
}

60
TD8/src/parking/Voiture.java Executable file
View File

@ -0,0 +1,60 @@
package parking;
public class Voiture {
private int nbPorte;
private double puissance;
private double kilometrage;
private String marque;
private double prix;
public Voiture() {
nbPorte = 0;
puissance = 0;
kilometrage = 0;
this.marque = null;
}
public Voiture(String marque, int date, double prixac, double cyl, int nbP, double pui, double kilo) {
nbPorte = nbP;
puissance = pui;
kilometrage = kilo;
this.marque = marque;
}
public int getNbPorte() {
return nbPorte;
}
public void setNbPorte(int nbPorte) {
this.nbPorte = nbPorte;
}
public double getPuissance() {
return puissance;
}
public void setPuissance(double puissance) {
this.puissance = puissance;
}
public double getKilometrage() {
return kilometrage;
}
public void setKilometrage(double kilometrage) {
this.kilometrage = kilometrage;
}
public String getMarque() {
return marque;
}
public void setMarque(String marque) {
this.marque = marque;
}
public void affiche() {
System.out.println(" Marque : "+this.marque+"\n Nb Portes : "+this.nbPorte+"\n Puissance "+this.puissance+"\n Kilometrage "+this.kilometrage+"\n Prix :"+this.prix+"");
}
}

116
TD8/src/pokemon/Joueur.java Executable file
View File

@ -0,0 +1,116 @@
package pokemon;
import java.util.*;
import java.lang.Math;
public class Joueur {
private String nom;
private int niveau; //Nombre pokemon captures
private int nbPoints; //Nombre pokemon actuel
private ArrayList<Pokemon> pokemon;
public Joueur() {
this.nom = null;
this.niveau = 1;
this.nbPoints = 0;
this.pokemon = new ArrayList<Pokemon>();
}
public Joueur(String s) {
this.nom = s;
this.niveau = 1;
this.nbPoints = 0;
this.pokemon = new ArrayList<Pokemon>();
}
public String toString() {
return "================================================================================\n" + "Le joueur " + this.nom + " a " + this.nbPoints + " pokemons sur lui et possede " + (this.niveau - 1) + " pokemons dans son PC !\nLes pokemons qu'il possede sont : " + this.pokemon.toString() + "\n================================================================================";
}
public double vitesseMoyenne() {
if(pokemon.isEmpty())
{
return 0;
}
double moyenne = 0.;
for (Pokemon p : pokemon) {
moyenne += p.calculerVitesse();
}
return moyenne/pokemon.size();
}
public double vitesseMoyenne(String s) {
int count = 0;
if(pokemon.isEmpty())
{
return 0;
}
double moyenne = 0.;
for (Pokemon p : pokemon) {
if(p.getType().getDescription().equals(s))
{
moyenne += p.calculerVitesse();
count++;
}
}
return moyenne/count;
}
public void attrapePokemon(Pokemon p){
this.niveau++;
this.nbPoints++;
this.pokemon.add(p);
}
public void relachePokemon(Pokemon p) {
this.nbPoints--;
this.pokemon.remove(p);
}
public void attack(Object obj) {
Joueur j = (Joueur)obj;
int x = (int)Math.random()*this.getPokemon().size();
int y = (int)Math.random()*j.getPokemon().size();
this.pokemon.get(x).attack(this.pokemon.get(y));
j.pokemon.get(y).attack(this.pokemon.get(x));
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public int getNiveau() {
return niveau;
}
public void setNiveau(int niveau) {
this.niveau = niveau;
}
public int getNbPoints() {
return nbPoints;
}
public void setNbPoints(int nbPoints) {
this.nbPoints = nbPoints;
}
public ArrayList<Pokemon> getPokemon() {
return pokemon;
}
public void setPokemon(ArrayList<Pokemon> pokemon) {
this.pokemon = pokemon;
}
}

92
TD8/src/pokemon/Pokemon.java Executable file
View File

@ -0,0 +1,92 @@
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;
}
@Override
public String toString() {
return this.getNom();
}
}

48
TD8/src/pokemon/PokemonEAU.java Executable file
View File

@ -0,0 +1,48 @@
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 this.getNom();
}
@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;
}
}

View File

@ -0,0 +1,56 @@
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 this.getNom();
}
@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;
}
}

47
TD8/src/pokemon/PokemonFEU.java Executable file
View File

@ -0,0 +1,47 @@
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 this.getNom();
}
@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;
}
}

View File

@ -0,0 +1,41 @@
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 this.getNom();
}
@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;
}
}

View File

@ -0,0 +1,69 @@
package pokemon;
public class TestPokemon {
@SuppressWarnings("unused")
public static void main(String[] args) {
//fire
PokemonFEU Infernape = new PokemonFEU("Infernape", 1.2, 55., 356, 45, 4);
PokemonFEU Ninetales = new PokemonFEU("Ninetales", 1.1, 19.9, 350, 26, 4);
PokemonFEU Salameche = new PokemonFEU("Salameche",0.5,5.,50,10,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);
PokemonELECTRIK Voltali = new PokemonELECTRIK("Voltali", 1.8, 47.3, 120, 130, 4, 0, 12);
PokemonELECTRIK Pikachu = new PokemonELECTRIK("Pikachu", 0.9, 5.3, 90, 50, 4, 0, 12);
//water
PokemonEAU Ludicolo = new PokemonEAU("Ludicolo", 1.5, 55., 364, 45, 2);
PokemonEAU Froakie = new PokemonEAU("Froakie", .3, 7., 286, 20, 2);
PokemonEAU Aquali = new PokemonEAU("Aquali", 2.1, 56.3, 140, 90, 3);
PokemonEAU Carapuce = new PokemonEAU("Carapuce",0.5,5.,50,10,0);
//grass
PokemonPLANTE Roselia = new PokemonPLANTE("Roselia", .3, 2., 304, 14);
PokemonPLANTE Torterra = new PokemonPLANTE("Torterra", 2.2, 310., 394, 44);
PokemonPLANTE Phylali = new PokemonPLANTE("Phylali", 1.6, 28.5, 130, 70);
PokemonPLANTE Herbizarre = new PokemonPLANTE("Herbizarre",0.5,5.,50,10);
Joueur JunkJumper = new Joueur("JunkJumper");
Joueur Mkel = new Joueur("Mkel");
JunkJumper.attrapePokemon(Infernape);
JunkJumper.attrapePokemon(Ampharos);
JunkJumper.attrapePokemon(Ludicolo);
JunkJumper.attrapePokemon(Roselia);
JunkJumper.attrapePokemon(Torterra);
JunkJumper.attrapePokemon(RaichuA);
JunkJumper.relachePokemon(Torterra);
JunkJumper.relachePokemon(RaichuA);
Mkel.attrapePokemon(Ampharos);
Mkel.attrapePokemon(RaichuA);
Mkel.attrapePokemon(Voltali);
Mkel.attrapePokemon(Pikachu);
Mkel.attrapePokemon(Infernape);
Mkel.attrapePokemon(Ninetales);
Mkel.attrapePokemon(Salameche);
Mkel.relachePokemon(Voltali);
Mkel.relachePokemon(Pikachu);
Mkel.relachePokemon(Infernape);
Mkel.relachePokemon(Ninetales);
System.out.println(JunkJumper.toString());
System.out.println(Mkel.toString());
System.out.println("Hello Pokeworld !");
}
}

19
TD8/src/pokemon/Type.java Executable file
View 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;
}
}

View File

@ -0,0 +1,38 @@
package services;
import java.util.*;
public class TestExercices {
@SuppressWarnings("unused")
public static void main(String[] args) {
int[] T1 = new int[10];
String[] T2 = new String[7];
int[] T3 = {0, 6, 2, 4, 3};
String[] T4 = {"bleu", "rouge", "blanc", "vert", "mauve", "indigo"};
/* 1 */ Arrays.fill(T1, 0, 10, 5);
/* 2 */ Arrays.fill(T2, 1, 3, "bleu");
/* 3 */ System.out.println(Arrays.toString(T1));
/* 3 */ System.out.println(Arrays.toString(T2));
/* 4 */ Arrays.sort(T3, 0, 5);
/* 5 */ Arrays.sort(T4, 0, 6);
/*
* System.out.println(Arrays.toString(T3));
* System.out.println(Arrays.toString(T4));
*/
/* 6 */ Arrays.equals(T1, T3);
/* 7 */ String[] T5 = Arrays.copyOf(T4, 5);//System.out.println(Arrays.toString(T5));
/* 8 */ String[] T6 = Arrays.copyOfRange(T4, 0, 6);//System.out.println(Arrays.toString(T6));
/* 9 */ List <String> T7 = Arrays.asList(T4); System.out.println(Arrays.toString(T6));
}
}

46
TD8/tests/testJoueurs.java Executable file
View File

@ -0,0 +1,46 @@
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import pokemon.*;
import org.junit.jupiter.api.Test;
class testJoueurs {
Joueur j1 = new Joueur("JunkJumper");
Joueur j2 = new Joueur("Rival");
PokemonELECTRIK p1 = new PokemonELECTRIK("Pikachu",0.5,5.,50,10,4,0,10);
PokemonPLANTE p2 = new PokemonPLANTE("Herbizarre",0.5,5.,50,10);
PokemonEAU p3 = new PokemonEAU("Carapuce",0.5,5.,50,10,0);
PokemonFEU p4 = new PokemonFEU("Salameche",0.5,5.,50,10,4);
@AfterEach
public void nettoyer() {
j1 = null;
j2 = null;
}
@Test
public void test()
{
j1.attrapePokemon(p1);
j2.attrapePokemon(p2);
j2.attrapePokemon(p4);
System.out.println("Debut du combat contre le rival :");
System.out.println(p1.getNom()+" a "+p1.getPv()+" pv");
System.out.println(p2.getNom()+" a "+p2.getPv()+" pv");
do {
j1.attack(j2);
j2.attack(j1);
System.out.println(p1.getNom()+" a "+p1.getPv()+" pv");
System.out.println(p2.getNom()+" a "+p2.getPv()+" pv");
}while ((p1.getPv() > 0) && (p2.getPv() > 0));
}
}