Aliza Lang пре 6 година
родитељ
комит
85e69af2e2
4 измењених фајлова са 86 додато и 5 уклоњено
  1. BIN
      Main.class
  2. 5
    0
      Main.ctxt
  3. 49
    5
      Main.java
  4. 32
    0
      package.bluej

+ 5
- 0
Main.ctxt Прегледај датотеку

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

+ 49
- 5
Main.java Прегледај датотеку

@@ -1,9 +1,53 @@
1
-/**
2
- * Created by iyasuwatts on 10/17/17.
3
- */
4
-public class Main {
1
+import java.util.*;
5 2
 
3
+public class Main {
6 4
     public static void main(String[] args){
5
+        Scanner in = new Scanner(System.in);
6
+        System.out.println("WELCOME! Guess a number between 1 and 49:");
7
+        int inputtedNumber = in.nextInt();
8
+        int previousInputNumber = 0;
7 9
         
10
+        int randomNumber = (int) (Math.random()*50);
11
+
12
+        int numberOfGuesses = 0;
13
+
14
+                    
15
+        String tryOrTries = "";
16
+        if (numberOfGuesses == 1){
17
+            tryOrTries ="try!";
18
+        }
19
+        else {
20
+            tryOrTries = "tries!";
21
+        }
22
+
23
+        while (true){
24
+            if(inputtedNumber < 1 || inputtedNumber > 49){
25
+                System.out.println("Guess a number between 1 and 49!");
26
+            }
27
+            else if(inputtedNumber < randomNumber && inputtedNumber > 0 && inputtedNumber < 50){
28
+
29
+               if (inputtedNumber != previousInputNumber){
30
+                numberOfGuesses = numberOfGuesses + 1;
31
+                }
32
+               System.out.println("TOO SMALL! Try again");
33
+            }
34
+            else if (inputtedNumber > randomNumber && inputtedNumber > 0 && inputtedNumber < 50){
35
+
36
+                if (inputtedNumber != previousInputNumber){
37
+                numberOfGuesses = numberOfGuesses + 1;
38
+                }
39
+                System.out.println("TOO LARGE! Try again!");
40
+            }
41
+            else if(inputtedNumber == randomNumber){
42
+
43
+                if (inputtedNumber != previousInputNumber){
44
+                numberOfGuesses = numberOfGuesses + 1;
45
+                }
46
+                System.out.println("CORRECT GUESS! You guessed the correct answer after " + numberOfGuesses + " "+ tryOrTries);
47
+                break;
48
+            }
49
+            previousInputNumber = inputtedNumber;
50
+            inputtedNumber = in.nextInt();
51
+        }  
8 52
     }
9
-}
53
+}

+ 32
- 0
package.bluej Прегледај датотеку

@@ -0,0 +1,32 @@
1
+#BlueJ package file
2
+editor.fx.0.height=804
3
+editor.fx.0.width=1427
4
+editor.fx.0.x=12
5
+editor.fx.0.y=23
6
+objectbench.height=101
7
+objectbench.width=461
8
+package.divider.horizontal=0.6
9
+package.divider.vertical=0.8007380073800738
10
+package.editor.height=427
11
+package.editor.width=674
12
+package.editor.x=640
13
+package.editor.y=42
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=Main
28
+target1.showInterface=false
29
+target1.type=ClassTarget
30
+target1.width=80
31
+target1.x=70
32
+target1.y=10