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