exo5: add a SortedMap from the TreeMap.
[Project_POO.git] / exo3 / Main.java
CommitLineData
fe98f4bd
JB
1import java.lang.reflect.Field;
2import java.lang.reflect.Method;
01bad5b3
JB
3import java.lang.reflect.Constructor;
4import java.lang.reflect.InvocationTargetException;
5import java.util.Scanner;
6import java.io.IOException;
e8b96f44
JB
7
8class Main {
9
10 private static void main_orig(String[] args) {
11 Entiers integer = new Entiers(5);
12
13 integer.inserer(1);
14
15 integer.afficher();
16
17 integer.inserer(12);
18
19 integer.afficher();
20
21 integer.inserer(3);
22
23 integer.afficher();
24
25 integer.inserer(0);
26
27 integer.inserer(1);
28
29 integer.afficher();
30
31 integer.supprimer(12);
32
33 integer.afficher();
34 System.out.println("Current size " + integer.getCurrentSize());
35
36 integer.supprimer(1);
37
38 integer.afficher();
39 System.out.println("Current size " + integer.getCurrentSize());
40
41 }
42
01bad5b3 43 private static void main_A(String[] args) {
03965cc6
JB
44 String className = null;
45 Scanner uInput = null;
46 try {
47 uInput = new Scanner(System.in);
48 System.out.println("Saisir le nom de la classe à inspecter:");
49 className = uInput.nextLine();
50 }
51 catch (Exception e) {
52 System.out.println("Erreur:");
53 e.printStackTrace();
54 }
55 finally {
56 uInput.close();
72fb6b7d 57 }
72fb6b7d 58
fe98f4bd
JB
59 Class cl = null;
60 try {
61 cl = Class.forName(className);
62 }
63 catch (ClassNotFoundException e) {
64 System.out.println("Entered class name do not exist.");
65 System.exit(-1);
66 }
67
68 Field[] fields = cl.getFields();
69 Method[] methods = cl.getMethods();
70
71 for (int i = 0; i < fields.length; i++) {
72 System.out.println(fields[i]);
73 }
74
75 for (int i = 0; i < methods.length; i++) {
76 System.out.println(methods[i]);
77 }
01bad5b3
JB
78 }
79
03965cc6 80 private static void main_B(String[] args) {
01bad5b3
JB
81 String name = Entiers.class.getName();
82 Class cl = null;
cc162028 83 Entiers o = null;
01bad5b3
JB
84 try {
85 cl = Class.forName(name);
cc162028 86 o = new Entiers(100);
01bad5b3
JB
87 }
88 catch (ClassNotFoundException e) {
89 System.out.println("Class name do not exist.");
90 System.exit(-1);
91 }
fe98f4bd 92
01bad5b3
JB
93 Scanner uInput = null;
94 try {
95 uInput = new Scanner(System.in);
96 System.out.println("Saisir le nom de la methode à invoquer:");
03965cc6 97 String method = uInput.nextLine();
01bad5b3
JB
98 //TODO: one can build the input list from the method arguments list and types
99 System.out.println("Saisir l'argument entier paramètre de la méthode:");
100 int integer = uInput.nextInt();
101 Method m = cl.getMethod(method, new Class[]{Integer.class});
102 m.invoke(o, integer);
103 }
104 catch (Exception e) {
105 System.out.println("Erreur:");
106 e.printStackTrace();
107 }
108 finally {
109 try {
110 Method mDisplay = cl.getMethod("afficher");
111 mDisplay.invoke(o);
112 }
113 catch (NoSuchMethodException e) {
114 e.printStackTrace();
115 }
116 catch (IllegalAccessException e) {
117 e.printStackTrace();
118 }
119 catch (InvocationTargetException e) {
120 e.printStackTrace();
121 }
122 uInput.close();
123 }
e8b96f44 124 }
03965cc6
JB
125
126 /**
127 * The main() function
128 * @param String[] args main() function arguments array
129 */
130 public static void main(String[] args) {
131 main_A(args);
132 }
e8b96f44 133}