Code cleanup : fix C style array declaration.
[Project_POO.git] / exo3 / Main.java
index 2b5ac8c9c8e5007ad0a4bcb8b1258c47b730d063..33f6bbc702a87b5cbb6f84224555508368e722df 100644 (file)
@@ -41,11 +41,20 @@ class Main {
     }
 
     private static void main_A(String[] args) {
-        if (args.length == 0) {
-            System.out.println("Please run with java Main <class name to inspect>");
-            System.exit(-1);
+        String className = null;
+        Scanner uInput = null;
+        try {
+            uInput = new Scanner(System.in);
+            System.out.println("Saisir le nom de la classe à inspecter:");
+            className = uInput.nextLine();
+        }
+        catch (Exception e) {
+            System.out.println("Erreur:");
+            e.printStackTrace();
+        }
+        finally {
+            uInput.close();
         }
-        String className = args[0];
 
         Class cl = null;
         try {
@@ -68,42 +77,24 @@ class Main {
         }
     }
 
-    /**
-     * The main() function
-     * @param String[] args main() function arguments array
-     */
-    public static void main(String[] args) {
+    private static void main_B(String[] args) {
         String name = Entiers.class.getName();
         Class cl = null;
-        Object o = null;
+        Entiers o = null;
         try {
             cl = Class.forName(name);
-            Class[] types = new Class[]{Integer.class};
-            Constructor ct = cl.getConstructor(types);
-            o = ct.newInstance(new Integer(100));
+            o = new Entiers(100);
         }
         catch (ClassNotFoundException e) {
             System.out.println("Class name do not exist.");
             System.exit(-1);
         }
-        catch (NoSuchMethodException e) {
-            e.printStackTrace();
-        }
-        catch (InstantiationException e) {
-            e.printStackTrace();
-        }
-        catch (IllegalAccessException e) {
-            e.printStackTrace();
-        }
-        catch (InvocationTargetException e) {
-            e.printStackTrace();
-        }
 
         Scanner uInput = null;
         try {
             uInput = new Scanner(System.in);
             System.out.println("Saisir le nom de la methode à invoquer:");
-            String method = uInput.next();
+            String method = uInput.nextLine();
             //TODO: one can build the input list from the method arguments list and types
             System.out.println("Saisir l'argument entier paramètre de la méthode:");
             int integer = uInput.nextInt();
@@ -131,4 +122,12 @@ class Main {
             uInput.close();
         }
     }
+
+    /**
+     * The main() function
+     * @param String[] args main() function arguments array
+     */
+    public static void main(String[] args) {
+        main_A(args);
+    }
 }