diff --git a/src/main/ui/Main.java b/src/main/ui/Main.java index e162902..afbbd5f 100644 --- a/src/main/ui/Main.java +++ b/src/main/ui/Main.java @@ -15,6 +15,7 @@ public class Main { //options = new Options(); System.out.println("Welcome to " + PROGRAM_NAME + "!"); guess(); + end(); } // java main @@ -40,8 +41,16 @@ public class Main { public int getUserInt() { Scanner scan = new Scanner(System.in); - int result = scan.nextInt(); - scan.close(); + int result = 0; + while (true) { + if (scan.hasNextInt()) { + result = scan.nextInt(); + break; + } else { + System.out.println("Try again?"); + scan.nextLine(); + } + } return result; } @@ -49,18 +58,18 @@ public class Main { if (user < secret || user > secret) { this.games++; System.out.println("Too bad. You guessed " - + secret + " with " + user + "."); + + secret + " with " + user + "."); } else { this.games++; this.win++; System.out.println("Wonderful! You have correctly guessed: " - + secret + " with " + user + "!"); + + secret + " with " + user + "!"); } } public void end() { System.out.println("You have won: " + this.win + " out of " + this.games - + "!"); + + "!"); System.out.println("Thank you for playing this game! Bye!"); } }