|
@@ -1,9 +1,53 @@
|
1
|
|
-/**
|
2
|
|
- * Created by iyasuwatts on 10/17/17.
|
3
|
|
- */
|
4
|
|
-public class Main {
|
|
1
|
+import java.util.*;
|
5
|
2
|
|
|
3
|
+public class Main {
|
6
|
4
|
public static void main(String[] args){
|
|
5
|
+ Scanner in = new Scanner(System.in);
|
|
6
|
+ System.out.println("WELCOME! Guess a number between 1 and 49:");
|
|
7
|
+ int inputtedNumber = in.nextInt();
|
|
8
|
+ int previousInputNumber = 0;
|
7
|
9
|
|
|
10
|
+ int randomNumber = (int) (Math.random()*50);
|
|
11
|
+
|
|
12
|
+ int numberOfGuesses = 0;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+ String tryOrTries = "";
|
|
16
|
+ if (numberOfGuesses == 1){
|
|
17
|
+ tryOrTries ="try!";
|
|
18
|
+ }
|
|
19
|
+ else {
|
|
20
|
+ tryOrTries = "tries!";
|
|
21
|
+ }
|
|
22
|
+
|
|
23
|
+ while (true){
|
|
24
|
+ if(inputtedNumber < 1 || inputtedNumber > 49){
|
|
25
|
+ System.out.println("Guess a number between 1 and 49!");
|
|
26
|
+ }
|
|
27
|
+ else if(inputtedNumber < randomNumber && inputtedNumber > 0 && inputtedNumber < 50){
|
|
28
|
+
|
|
29
|
+ if (inputtedNumber != previousInputNumber){
|
|
30
|
+ numberOfGuesses = numberOfGuesses + 1;
|
|
31
|
+ }
|
|
32
|
+ System.out.println("TOO SMALL! Try again");
|
|
33
|
+ }
|
|
34
|
+ else if (inputtedNumber > randomNumber && inputtedNumber > 0 && inputtedNumber < 50){
|
|
35
|
+
|
|
36
|
+ if (inputtedNumber != previousInputNumber){
|
|
37
|
+ numberOfGuesses = numberOfGuesses + 1;
|
|
38
|
+ }
|
|
39
|
+ System.out.println("TOO LARGE! Try again!");
|
|
40
|
+ }
|
|
41
|
+ else if(inputtedNumber == randomNumber){
|
|
42
|
+
|
|
43
|
+ if (inputtedNumber != previousInputNumber){
|
|
44
|
+ numberOfGuesses = numberOfGuesses + 1;
|
|
45
|
+ }
|
|
46
|
+ System.out.println("CORRECT GUESS! You guessed the correct answer after " + numberOfGuesses + " "+ tryOrTries);
|
|
47
|
+ break;
|
|
48
|
+ }
|
|
49
|
+ previousInputNumber = inputtedNumber;
|
|
50
|
+ inputtedNumber = in.nextInt();
|
|
51
|
+ }
|
8
|
52
|
}
|
9
|
|
-}
|
|
53
|
+}
|