Fixed bugs.

deliverable_2
asdfasdf 6 years ago
parent d3f2297d27
commit 15f2aac1a8

@ -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!");
}
}

Loading…
Cancel
Save