Ver código fonte

created a guessing game

Margaret Pierse 6 anos atrás
pai
commit
c0ed709695

+ 12
- 0
TooLargeTooSmall/README.TXT Ver arquivo

@@ -0,0 +1,12 @@
1
+------------------------------------------------------------------------
2
+This is the project README file. Here, you should describe your project.
3
+Tell the reader (someone who does not know anything about this project)
4
+all he/she needs to know. The comments should usually include at least:
5
+------------------------------------------------------------------------
6
+
7
+PROJECT TITLE:
8
+PURPOSE OF PROJECT:
9
+VERSION or DATE:
10
+HOW TO START THIS PROJECT:
11
+AUTHORS:
12
+USER INSTRUCTIONS:

BIN
TooLargeTooSmall/guessingGame.class Ver arquivo


+ 6
- 0
TooLargeTooSmall/guessingGame.ctxt Ver arquivo

@@ -0,0 +1,6 @@
1
+#BlueJ class context
2
+comment0.target=guessingGame
3
+comment0.text=\n\ Write\ a\ description\ of\ class\ guessingGame\ here.\n\n\ @author\ Maggie\n\ @version\ 10/19/18\n
4
+comment1.params=
5
+comment1.target=void\ guessIt()
6
+numComments=2

+ 50
- 0
TooLargeTooSmall/guessingGame.java Ver arquivo

@@ -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
+}

+ 32
- 0
TooLargeTooSmall/package.bluej Ver arquivo

@@ -0,0 +1,32 @@
1
+#BlueJ package file
2
+editor.fx.0.height=722
3
+editor.fx.0.width=800
4
+editor.fx.0.x=2419
5
+editor.fx.0.y=130
6
+objectbench.height=101
7
+objectbench.width=488
8
+package.divider.horizontal=0.592814371257485
9
+package.divider.vertical=0.8304552590266876
10
+package.editor.height=522
11
+package.editor.width=729
12
+package.editor.x=1446
13
+package.editor.y=115
14
+package.frame.height=695
15
+package.frame.width=855
16
+package.numDependencies=0
17
+package.numTargets=1
18
+package.showExtends=true
19
+package.showUses=true
20
+project.charset=UTF-8
21
+readme.height=58
22
+readme.name=@README
23
+readme.width=47
24
+readme.x=10
25
+readme.y=10
26
+target1.height=50
27
+target1.name=guessingGame
28
+target1.showInterface=false
29
+target1.type=ClassTarget
30
+target1.width=120
31
+target1.x=124
32
+target1.y=178