|
@@ -3,7 +3,36 @@
|
3
|
3
|
*/
|
4
|
4
|
public class Main {
|
5
|
5
|
|
|
6
|
+ int randomNum;
|
|
7
|
+ int counterTooBig = 0;
|
|
8
|
+ int counterTooSmall = 0;
|
|
9
|
+ int totalGuesses = 0;
|
|
10
|
+ int prevGuess = 0;
|
|
11
|
+ int currentGuess = 0;
|
|
12
|
+
|
6
|
13
|
public static void main(String[] args){
|
7
|
|
-
|
|
14
|
+ System.out.println("You have 5 chances to correctly guess a random number between 1 and 20.");
|
|
15
|
+ Scanner input = new Scanner(System.in);
|
|
16
|
+ Random random = new Random();
|
|
17
|
+ randomNum = 1+random.nextInt(20);
|
|
18
|
+ System.out.println("Enter your first guess now: ");
|
|
19
|
+ for (int i = 1; i <= 5; i++){
|
|
20
|
+ currentGuess = input.getNextInt();
|
|
21
|
+ if (currentGuess == prevGuess) {
|
|
22
|
+ i=i-1;
|
|
23
|
+ System.out.println("Same as your last guess...Try Again")
|
|
24
|
+ }
|
|
25
|
+ if (currentGuess == randomNum) {
|
|
26
|
+ System.out.println("*** Correct!!! ***");
|
|
27
|
+ System.out.println("Total guesses to win: " + i);
|
|
28
|
+ }else if (currentGuess > randomNum) {
|
|
29
|
+ System.out.println("TOO BIG");
|
|
30
|
+ System.out.println("Total guesses remaining: " + (5-i));
|
|
31
|
+ } else if (currentGuess < randomNum) {
|
|
32
|
+ System.out.println("too small");
|
|
33
|
+ System.out.println("Total guesses remaining: " + (5-i));
|
|
34
|
+ prevGuess = currentGuess;
|
|
35
|
+ }
|
|
36
|
+ }
|
8
|
37
|
}
|
9
|
38
|
}
|