#33 4.2_JevitTith_TooLargeTooSmall-BlueJ_Lab

Aperto
jtith vorrebbe unire 2 commit da jtith/ZCW-TooLargeTooSmall-BlueJ:master a master

BIN
GuessingGame/GuessingGame.class Vedi File


+ 7
- 0
GuessingGame/GuessingGame.ctxt Vedi File

@@ -0,0 +1,7 @@
1
+#BlueJ class context
2
+comment0.target=GuessingGame
3
+comment1.params=args
4
+comment1.target=void\ main(java.lang.String[])
5
+comment2.params=
6
+comment2.target=void\ takeGuess()
7
+numComments=3

+ 34
- 0
GuessingGame/GuessingGame.java Vedi File

@@ -0,0 +1,34 @@
1
+import java.util.HashSet;
2
+import java.util.Random;
3
+import java.util.Scanner;
4
+
5
+public class GuessingGame {
6
+    private static Integer guessedNumber;
7
+    private static HashSet<Integer> numberOfAttempts = new HashSet<Integer>();
8
+
9
+        public static void main(String[] args){
10
+            System.out.println("Guess a whole number within the ranges  (1 ≤ x ≤ 10)");
11
+            takeGuess();
12
+            Random random = new Random();
13
+            Integer randomNumber =random.nextInt(10) + 1;
14
+                while (!guessedNumber.equals(randomNumber)) {
15
+                    if (guessedNumber < randomNumber) {
16
+                        System.out.println("Too Low");
17
+                        takeGuess();
18
+                    } else if (guessedNumber > randomNumber){
19
+                        System.out.println("Too High");
20
+                        takeGuess();
21
+                    }
22
+                }
23
+                System.out.println("Correct! " + " number of attempts = " + numberOfAttempts.size());
24
+            System.out.println("List of your guesses " + numberOfAttempts);
25
+        }
26
+
27
+        public static void takeGuess() {
28
+            Scanner userInput = new Scanner(System.in);
29
+            guessedNumber = userInput.nextInt();
30
+            numberOfAttempts.add(guessedNumber);
31
+        }
32
+
33
+
34
+}

+ 12
- 0
GuessingGame/README.TXT Vedi File

@@ -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:

+ 32
- 0
GuessingGame/package.bluej Vedi File

@@ -0,0 +1,32 @@
1
+#BlueJ package file
2
+editor.fx.0.height=739
3
+editor.fx.0.width=816
4
+editor.fx.0.x=705
5
+editor.fx.0.y=260
6
+objectbench.height=93
7
+objectbench.width=760
8
+package.divider.horizontal=0.6
9
+package.divider.vertical=0.8
10
+package.editor.height=393
11
+package.editor.width=670
12
+package.editor.x=951
13
+package.editor.y=20
14
+package.frame.height=600
15
+package.frame.width=800
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=70
32
+target1.y=10

+ 34
- 9
Main.java Vedi File

@@ -1,9 +1,34 @@
1
-/**
2
- * Created by iyasuwatts on 10/17/17.
3
- */
4
-public class Main {
5
-
6
-    public static void main(String[] args){
7
-        
8
-    }
9
-}
1
+import java.util.HashSet;
2
+import java.util.Random;
3
+import java.util.Scanner;
4
+
5
+public class GuessingGame {
6
+    private static Integer guessedNumber;
7
+    private static HashSet<Integer> numberOfAttempts = new HashSet<Integer>();
8
+
9
+        public static void main(String[] args){
10
+            System.out.println("Guess a whole number within the ranges  (1 ≤ x ≤ 10)");
11
+            takeGuess();
12
+            Random random = new Random();
13
+            Integer randomNumber =random.nextInt(10) + 1;
14
+                while (!guessedNumber.equals(randomNumber)) {
15
+                    if (guessedNumber < randomNumber) {
16
+                        System.out.println("Too Low");
17
+                        takeGuess();
18
+                    } else if (guessedNumber > randomNumber){
19
+                        System.out.println("Too High");
20
+                        takeGuess();
21
+                    }
22
+                }
23
+                System.out.println("Correct! " + " number of attempts = " + numberOfAttempts.size());
24
+            System.out.println("List of your guesses " + numberOfAttempts);
25
+        }
26
+
27
+        public static void takeGuess() {
28
+            Scanner userInput = new Scanner(System.in);
29
+            guessedNumber = userInput.nextInt();
30
+            numberOfAttempts.add(guessedNumber);
31
+        }
32
+
33
+
34
+}