X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=exo3%2FMain.java;h=33f6bbc702a87b5cbb6f84224555508368e722df;hb=03965cc6b87f9dc601f1fd14e33b519cd78caeac;hp=2b5ac8c9c8e5007ad0a4bcb8b1258c47b730d063;hpb=01bad5b37bf95f027f583e1b1da607e074050651;p=Project_POO.git diff --git a/exo3/Main.java b/exo3/Main.java index 2b5ac8c..33f6bbc 100644 --- a/exo3/Main.java +++ b/exo3/Main.java @@ -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 "); - 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); + } }