|
@@ -0,0 +1,50 @@
|
|
1
|
+import java.util.*;
|
|
2
|
+/**
|
|
3
|
+ * Write a description of class guessingGame here.
|
|
4
|
+ *
|
|
5
|
+ * @author Maggie
|
|
6
|
+ * @version 10/19/18
|
|
7
|
+ */
|
|
8
|
+public class guessingGame
|
|
9
|
+{
|
|
10
|
+
|
|
11
|
+ public void guessIt()
|
|
12
|
+ {
|
|
13
|
+ Random rand = new Random();
|
|
14
|
+ int randomNum = rand.nextInt(11);
|
|
15
|
+ boolean[] usedBefore = new boolean[11];
|
|
16
|
+ int userGuess = 0;
|
|
17
|
+ for (int i=0; i<11; i++) {
|
|
18
|
+ usedBefore[i] = false;
|
|
19
|
+ System.out.println(usedBefore[i]);
|
|
20
|
+ }
|
|
21
|
+ while (userGuess != randomNum){
|
|
22
|
+ System.out.print("Guess a number from 0-10! \n");
|
|
23
|
+ Scanner userInput = new Scanner(System.in);
|
|
24
|
+ userGuess = userInput.nextInt();
|
|
25
|
+
|
|
26
|
+ if (userGuess >10 || userGuess < 0) {
|
|
27
|
+ System.out.println("Your number was out of range");
|
|
28
|
+
|
|
29
|
+ } else if(!usedBefore[userGuess]){
|
|
30
|
+ if (userGuess == randomNum) {
|
|
31
|
+ System.out.println("Yay! That guess is correct!");
|
|
32
|
+ } else if
|
|
33
|
+ (userGuess > randomNum) {
|
|
34
|
+ System.out.println("Guess again :( Your guess was too high.");
|
|
35
|
+ usedBefore[userGuess] = true;
|
|
36
|
+
|
|
37
|
+ } else if
|
|
38
|
+ (userGuess < randomNum) {
|
|
39
|
+ System.out.println("Guess again :( Your guess was too low.");
|
|
40
|
+ usedBefore[userGuess] = true;
|
|
41
|
+
|
|
42
|
+ }
|
|
43
|
+ } else if (usedBefore[userGuess]) {
|
|
44
|
+ System.out.print("Hey! You already guessed that number!");
|
|
45
|
+
|
|
46
|
+ }}
|
|
47
|
+
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+}
|