From: Jérôme Benoit Date: Thu, 5 Apr 2018 13:38:55 +0000 (+0200) Subject: exo3: use Scanner class in more places. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=03965cc6b87f9dc601f1fd14e33b519cd78caeac;p=Project_POO.git exo3: use Scanner class in more places. Signed-off-by: Jérôme Benoit --- diff --git a/exo3/Main.java b/exo3/Main.java index e92a5e2..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,11 +77,7 @@ 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; Entiers o = null; @@ -89,7 +94,7 @@ class Main { 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(); @@ -117,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); + } }