diff options
Diffstat (limited to 'sem_5/HLIN505_Java/HLIN505/src/tp7')
| -rw-r--r-- | sem_5/HLIN505_Java/HLIN505/src/tp7/Ex1.java | 59 | ||||
| -rw-r--r-- | sem_5/HLIN505_Java/HLIN505/src/tp7/ManipAnnot.java | 5 | ||||
| -rw-r--r-- | sem_5/HLIN505_Java/HLIN505/src/tp7/Persobonus.java | 17 | ||||
| -rw-r--r-- | sem_5/HLIN505_Java/HLIN505/src/tp7/Persoinvisible.java | 24 | ||||
| -rw-r--r-- | sem_5/HLIN505_Java/HLIN505/src/tp7/Personnage.java | 35 | ||||
| -rw-r--r-- | sem_5/HLIN505_Java/HLIN505/src/tp7/Todo.java | 7 | ||||
| -rw-r--r-- | sem_5/HLIN505_Java/HLIN505/src/tp7/fabriquePerso.java | 38 |
7 files changed, 185 insertions, 0 deletions
diff --git a/sem_5/HLIN505_Java/HLIN505/src/tp7/Ex1.java b/sem_5/HLIN505_Java/HLIN505/src/tp7/Ex1.java new file mode 100644 index 0000000..1a6116d --- /dev/null +++ b/sem_5/HLIN505_Java/HLIN505/src/tp7/Ex1.java @@ -0,0 +1,59 @@ +package tp7;
+
+import java.util.ArrayList;
+
+import javax.swing.JTextField;
+
+import java.io.File;
+import java.lang.reflect.*;
+
+public class Ex1 {
+ private ArrayList Liste;
+ public Ex1 (ArrayList a) {
+ Liste=a;
+ }
+ public Method[] methodesdei (int i) {
+ Class cl = Liste.get(i).getClass();
+ Method[] m = cl.getMethods();
+ return m;
+ }
+ public Class superclasse() {
+ Class ret;
+ ArrayList<Class> cl= new ArrayList<Class>();
+ for (int i = 0; i < Liste.size(); i++) {
+ cl.add(Liste.get(i).getClass());
+ }
+ ArrayList<Class> cl2 = new ArrayList<Class>();
+ while (cl2.add(cl.get(0).getSuperclass()));
+ Object tmp2=new Object();
+ ret = tmp2.getClass();
+ for (Class tmp : cl2) {
+ Boolean fornow = true;
+ for (int i = 1; i < Liste.size(); i ++) {
+ if (!tmp.isInstance(Liste.get(i))){
+ fornow = false;
+ }
+ }
+ if (fornow) {
+ ret = tmp;
+ break;
+ }
+ }
+ return ret;
+ }
+
+ public <T> void add (T obj) {
+ Liste.add(obj);
+ }
+
+ public static void main (String[] args) {
+ ArrayList<Object> list = new ArrayList<Object>();
+ list.add(new Integer(12));
+ list.add(new String("allo"));
+ list.add(new Double(12.2311));
+ list.add(new File("."));
+ list.add(new JTextField());
+ Ex1 test = new Ex1(list);
+ System.out.println(test.superclasse());
+ }
+}
diff --git a/sem_5/HLIN505_Java/HLIN505/src/tp7/ManipAnnot.java b/sem_5/HLIN505_Java/HLIN505/src/tp7/ManipAnnot.java new file mode 100644 index 0000000..2b4dcd6 --- /dev/null +++ b/sem_5/HLIN505_Java/HLIN505/src/tp7/ManipAnnot.java @@ -0,0 +1,5 @@ +package tp7;
+
+public class ManipAnnot {
+
+}
diff --git a/sem_5/HLIN505_Java/HLIN505/src/tp7/Persobonus.java b/sem_5/HLIN505_Java/HLIN505/src/tp7/Persobonus.java new file mode 100644 index 0000000..9b74195 --- /dev/null +++ b/sem_5/HLIN505_Java/HLIN505/src/tp7/Persobonus.java @@ -0,0 +1,17 @@ +package tp7;
+
+public class Persobonus extends Personnage{
+ private int palier;
+ public void setpoint (int point) {
+ super.setpoint(point+super.getpoint());
+ if (getpoint()/palier>0) {
+ setUp(getUp()+getpoint()/palier);
+ super.setpoint(getpoint()%palier);
+ }
+ }
+ public Persobonus(String nom, int point, int Up, int palier) {
+ super(nom,point,Up);
+ this.palier=palier;
+ this.setpoint(0);
+ }
+}
diff --git a/sem_5/HLIN505_Java/HLIN505/src/tp7/Persoinvisible.java b/sem_5/HLIN505_Java/HLIN505/src/tp7/Persoinvisible.java new file mode 100644 index 0000000..5599ddb --- /dev/null +++ b/sem_5/HLIN505_Java/HLIN505/src/tp7/Persoinvisible.java @@ -0,0 +1,24 @@ +package tp7;
+
+public class Persoinvisible extends Personnage {
+ private Boolean visible;
+ private int invtime;
+ private int cd;
+ public void devenirInvisible() {
+ visible=false;
+ invtime=5;
+ }
+ public void devenirVisible() {
+ visible = true;
+ invtime=0;
+ cd = 5;
+ }
+ @Todo(type="Incroyable", version="0.12", dureeapprox=120)
+
+ public Persoinvisible (String nom, int point, int Up, Boolean visible, int invtime, int cd) {
+ super(nom,point,Up);
+ this.visible=visible;
+ this.invtime=invtime;
+ this.cd=cd;
+ }
+}
diff --git a/sem_5/HLIN505_Java/HLIN505/src/tp7/Personnage.java b/sem_5/HLIN505_Java/HLIN505/src/tp7/Personnage.java new file mode 100644 index 0000000..2d1a8ff --- /dev/null +++ b/sem_5/HLIN505_Java/HLIN505/src/tp7/Personnage.java @@ -0,0 +1,35 @@ +package tp7;
+
+public abstract class Personnage {
+ private String nom;
+ private int point;
+ private int up;
+ public String getNom() {
+ return nom;
+ }
+ public void setNom(String nom) {
+ this.nom = nom;
+ }
+ public int getpoint() {
+ return point;
+ }
+ public void setpoint(int point) {
+ this.point = point;
+ }
+ public int getUp() {
+ return up;
+ }
+ public void setUp(int up) {
+ this.up = up;
+ }
+ public Personnage (String nom, int point, int Up) {
+ this.nom=nom;
+ this.point=point;
+ this.up=Up;
+ }
+ public Personnage() {
+ nom="defaut";
+ point=0;
+ up=3;
+ }
+}
diff --git a/sem_5/HLIN505_Java/HLIN505/src/tp7/Todo.java b/sem_5/HLIN505_Java/HLIN505/src/tp7/Todo.java new file mode 100644 index 0000000..2ce9318 --- /dev/null +++ b/sem_5/HLIN505_Java/HLIN505/src/tp7/Todo.java @@ -0,0 +1,7 @@ +package tp7;
+
+public @interface Todo {
+ String type();
+ String version();
+ int dureeapprox();
+}
\ No newline at end of file diff --git a/sem_5/HLIN505_Java/HLIN505/src/tp7/fabriquePerso.java b/sem_5/HLIN505_Java/HLIN505/src/tp7/fabriquePerso.java new file mode 100644 index 0000000..5123c79 --- /dev/null +++ b/sem_5/HLIN505_Java/HLIN505/src/tp7/fabriquePerso.java @@ -0,0 +1,38 @@ +package tp7;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+
+public class fabriquePerso {
+ public Personnage creer(String name) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
+ if (name.equals("Persoinvisible") || name.equals("Persobonus")) {
+ Class t = Class.forName(name);
+ Personnage ret = (Personnage) t.newInstance();
+ return ret;
+ }
+ else {
+ return null;
+ }
+ }
+ public Personnage ficheperso (Personnage pers) {
+ Class c=pers.getClass();
+ Field[] fields = c.getDeclaredFields();
+ ArrayList<Field> AF = tabtoarray(fields);
+ Method[] Methodes = c.getDeclaredMethods();
+ while ((c=c.getSuperclass()) != null) {
+ Field[] tmp = c.getDeclaredFields();
+ for (Field f : tmp) {
+ AF.add(f);
+ }
+
+ }
+ System.out.println("Entrer");
+ }
+ public ArrayList<Field> tabtoarray(Field[] f){
+ ArrayList<Field> ret = new ArrayList<Field>();
+ for (int i =0; i < f.length; i ++) {
+ ret.add(f[i]);
+ }
+ return ret;
+ }
+}
|
