Fixed bugs.

deliverable_2
asdfasdf 6 years ago
parent d3f2297d27
commit 15f2aac1a8

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

Loading…
Cancel
Save