|
@@ -0,0 +1,43 @@
|
|
1
|
+import java.util.*;
|
|
2
|
+import java.util.Random;
|
|
3
|
+/**
|
|
4
|
+ * Too Large Too Small Guessing Game.
|
|
5
|
+ *
|
|
6
|
+ * @jaejoson
|
|
7
|
+ * @10/18/2018
|
|
8
|
+ */
|
|
9
|
+public class GuessingGame {
|
|
10
|
+
|
|
11
|
+ public static void main(String[] args) {
|
|
12
|
+ double rand = Math.random() * ((50 - 25) + 1) + 25;
|
|
13
|
+ double Val = Math.round(rand);
|
|
14
|
+ int numberOfTries = 0;
|
|
15
|
+ int previousGuess = 0;
|
|
16
|
+ while (true) {
|
|
17
|
+ Scanner in = new Scanner(System.in);
|
|
18
|
+ System.out.print("Guess a number between 25 and 50. ");
|
|
19
|
+ int userGuess = in.nextInt();
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+ if (previousGuess != userGuess) {
|
|
23
|
+ numberOfTries++;
|
|
24
|
+ previousGuess = userGuess;
|
|
25
|
+ }
|
|
26
|
+
|
|
27
|
+ if (userGuess != Val && userGuess > Val) {
|
|
28
|
+ System.out.print("Number is waaaay too large! ");
|
|
29
|
+ } else if (userGuess != Val && userGuess < Val) {
|
|
30
|
+ System.out.print("Number is too small :( ");
|
|
31
|
+ } else {
|
|
32
|
+ System.out.print("You got the correct guess! ");
|
|
33
|
+ System.out.print("It took you " + numberOfTries + " tries.");
|
|
34
|
+ break;
|
|
35
|
+ }
|
|
36
|
+
|
|
37
|
+ }
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+ }
|
|
43
|
+}
|