|
@@ -0,0 +1,42 @@
|
|
1
|
+
|
|
2
|
+/**
|
|
3
|
+ * Write a description of class GuessingGame here.
|
|
4
|
+ *
|
|
5
|
+ * @author (Zavon Malone)
|
|
6
|
+ * @version (10/21/18)
|
|
7
|
+ */
|
|
8
|
+import java.util.Scanner;
|
|
9
|
+import java.util.Random;
|
|
10
|
+public class GuessingGame
|
|
11
|
+{
|
|
12
|
+ public static void guess (String [] args){
|
|
13
|
+ Random randomNumber = new Random();
|
|
14
|
+ Scanner game = new Scanner(System.in);
|
|
15
|
+ int computerValue = randomNumber.nextInt(100);
|
|
16
|
+ int numberOfTries = 0;
|
|
17
|
+ int success = 0;
|
|
18
|
+ int guess = 0;
|
|
19
|
+
|
|
20
|
+ while(true){
|
|
21
|
+ computerValue = randomNumber.nextInt(100);
|
|
22
|
+ numberOfTries = 0;
|
|
23
|
+ while (true) {
|
|
24
|
+ System.out.println("Enter your best guess between 1 and 100");
|
|
25
|
+ guess = game.nextInt();
|
|
26
|
+ numberOfTries++;
|
|
27
|
+
|
|
28
|
+ if (guess < 1 || guess > 100) System.out.println("Invalid input");
|
|
29
|
+ else if (guess == computerValue){
|
|
30
|
+ System.out.println("YOU'RE RIGHT. Amount of attempts: " + numberOfTries + ", the number was" + computerValue);
|
|
31
|
+ break;
|
|
32
|
+
|
|
33
|
+ }
|
|
34
|
+ else if (guess < computerValue) System.out.println("Your guess is to low!");
|
|
35
|
+ else if (guess > computerValue) System.out.println("Your guess is to high!");
|
|
36
|
+ }
|
|
37
|
+ System.out.println("Try Again? (1:Yes/2:No)");
|
|
38
|
+ if(game.nextInt() != 1) break;
|
|
39
|
+ }
|
|
40
|
+
|
|
41
|
+ }
|
|
42
|
+}
|