Refonte du repo

This commit is contained in:
JunkJumper
2020-05-20 17:01:49 +02:00
parent 4962efbd17
commit 45f4d2dffe
165 changed files with 83943 additions and 84353 deletions

View File

@ -0,0 +1,10 @@
package comparable;
public class ComparetoDepNom /*implements comparator<Personne>*/ {
public int compare(Personne p1, Personne p2) {
//int r = p1.dept.compareTo(p2.dept);
return 0;
}
}

View File

@ -0,0 +1,48 @@
package comparable;
public class Enseignant extends Personne{
private String matiere;
public Enseignant() {
super.setAge(0);
super.setNom(null);
this.matiere = null;
}
public Enseignant(String s, int i, String m) {
super.setAge(i);
super.setNom(s);
this.matiere = m;
}
public int compareTo(Personne autre)
{
return this.getNom().compareTo(autre.getNom());
}
public String toString() {
return super.toString() + " et enseigne la matiere \"" + this.matiere + "\"";
}
/**
* @return the matiere
*/
public String getMatiere() {
return matiere;
}
/**
* @param matiere the matiere to set
*/
public void setMatiere(String matiere) {
this.matiere = matiere;
}
}

View File

@ -0,0 +1,53 @@
package comparable;
public class Etudiant extends Personne{
private String classe;
private int numEtu;
public Etudiant() {
super.setAge(0);
super.setNom(null);
this.classe = null;
}
public Etudiant(String s, int i, String c) {
super.setAge(i);
super.setNom(s);
this.classe = c;
}
public String toString() {
return super.toString() + " et est en classe de " + this.classe;
}
/**
* @return the numEtu
*/
public int getNumEtu() {
return numEtu;
}
/**
* @param numEtu the numEtu to set
*/
public void setNumEtu(int numEtu) {
this.numEtu = numEtu;
}
/**
* @return the classe
*/
public String getClasse() {
return classe;
}
/**
* @param classe the classe to set
*/
public void setClasse(String classe) {
this.classe = classe;
}
}

View File

@ -0,0 +1,57 @@
package comparable;
public abstract class Personne implements Comparable<Personne>{
private String nom;
private int age;
public Personne() {
this.nom = null;
this.age = 0;
}
public Personne(String s, int i) {
this.nom = s;
this.age = i;
}
public int compareTo(Personne p)
{
return this.getNom().compareTo(p.getNom());
}
public String toString() {
return this.nom + " a " + this.age + " ans";
}
/**
* @return the nom
*/
public String getNom() {
return nom;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(int age) {
this.age = age;
}
/**
* @param nom the nom to set
*/
public void setNom(String nom) {
this.nom = nom;
}
}

View File

@ -0,0 +1,40 @@
package comparable;
import java.util.*;
public class main {
public static void main(String[] args) {
Personne bart = new Etudiant("Bart", 15, "2nde");
Personne tom = new Etudiant("Tom", 13, "4eme");
Personne max = new Etudiant("Max", 18, "Terminale");
Personne thibault = new Enseignant("Tibault", 41, "Mathematiques");
List <Personne> w = new ArrayList<Personne>();
w.add(bart);
w.add(tom);
w.add(max);
w.add(thibault);
for (Personne p : w){
System.out.println(p.toString());
}
Collections.sort(w);
System.out.println("===================");
for (Personne p : w){
System.out.println(p.toString());
}
System.out.println("Hello World !");
}
}

121
src/TD9/pokemon/Joueur.java Normal file
View File

@ -0,0 +1,121 @@
package pokemon;
import java.util.*;
import java.lang.Math;
public class Joueur implements Comparable<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.niveau + " pokemons!\nLes pokemons qu'il possede sont : " + this.pokemon.toString() + "\n================================================================================";
}
public int compareTo(Joueur j)
{
return this.getNom().compareTo(j.getNom());
}
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;
}
}

View File

@ -0,0 +1,106 @@
package pokemon;
public abstract class Pokemon implements Comparable<Pokemon> {
private String nom;
private double taille; // en m
private double poids; // en kg
private int pv;
private int pc;
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();
}
public int compareTo(Pokemon p)
{
int r = this.getType().getDescription().compareTo(p.getType().getDescription());
if (r == 0) {
return this.getPv() - p.getPv();
}
else {
return r;
}
}
//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;
}
}

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

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,106 @@
package pokemon;
import java.util.*;
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");
ArrayList<Pokemon> l1 = new ArrayList<Pokemon>();
ArrayList<Pokemon> l2 = new ArrayList<Pokemon>();
l1.add(Infernape);
l1.add(Ludicolo);
l1.add(Roselia);
l1.add(Ampharos);
l2.add(Voltali);
l2.add(Salameche);
l2.add(Froakie);
l2.add(Herbizarre);
l2.add(Torterra);
l2.add(Carapuce);
l2.add(Ninetales);
JunkJumper.setPokemon(l1);
Mkel.setPokemon(l2);
System.out.println("===== Collection 1 : =====");;
for (Pokemon pokemon : l1) {
System.out.println(pokemon.toString());
}
System.out.println("===== Collection 2 : =====");;
for (Pokemon pokemon : l2) {
System.out.println(pokemon.toString());
}
Collections.sort(l1);
Collections.sort(l2);
JunkJumper.setNiveau(4);
Mkel.setNiveau(7);
System.out.println("\n Tri par nom effectue");
System.out.println("===== Collection 1 : =====");;
for (Pokemon pokemon : l1) {
System.out.println(pokemon.toString());
}
System.out.println("===== Collection 2 : =====");;
for (Pokemon pokemon : l2) {
System.out.println(pokemon.toString());
}
ArrayList<Joueur> lj = new ArrayList<Joueur>();
lj.add(JunkJumper);
lj.add(Mkel);
for (Joueur joueur : lj) {
System.out.println(joueur.toString());
}
Collections.sort(lj);
System.out.println("\n Tri par nom effectue");
for (Joueur joueur : lj) {
System.out.println(joueur.toString());
}
System.out.println("Hello Pokeworld !");
}
}

19
src/TD9/pokemon/Type.java Normal 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;
}
}