Browse Source

Lab Update

Yauheni Papko 6 years ago
parent
commit
ea4960ecb8
6 changed files with 105 additions and 4 deletions
  1. BIN
      .DS_Store
  2. 54
    4
      Main.java
  3. 12
    0
      README.TXT
  4. BIN
      main.class
  5. 7
    0
      main.ctxt
  6. 32
    0
      package.bluej

BIN
.DS_Store View File


+ 54
- 4
Main.java View File

@@ -1,9 +1,59 @@
1
+
1 2
 /**
2
- * Created by iyasuwatts on 10/17/17.
3
+ * Write a description of class main here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
3 7
  */
4
-public class Main {
5 8
 
6
-    public static void main(String[] args){
7
-        
9
+import java.util.Scanner;
10
+import java.util.Random;
11
+import java.util.InputMismatchException;
12
+
13
+public class main
14
+{
15
+    static Scanner in = new Scanner(System.in);
16
+    public static void main(String[] args ){
17
+        Random rand = new Random();
18
+        int mysteryNumber = rand.nextInt(100);
19
+        int count=0;
20
+        int guess=-1;
21
+        int previousGuess=-1;
22
+        System.out.println("Let\'s guess a number between 0 and 99: ");
23
+        while (guess != mysteryNumber) {
24
+            guess = GetAnInteger();
25
+            if (guess < 0 || guess>99) {
26
+                System.out.println("Invalid input! Try again!");
27
+            } else if (guess > mysteryNumber) {
28
+                System.out.println("Too large!");
29
+            } else if (guess < mysteryNumber) {
30
+                System.out.println("Too small!");
31
+            } else if (guess == mysteryNumber) {
32
+                System.out.println("You got it!");
33
+            }
34
+
35
+            //don't count consecutive and invalid inputs
36
+            if (guess != previousGuess && guess >= 0 && guess<=99) {
37
+                count++;
38
+            }
39
+            previousGuess = guess;
40
+        }
41
+        System.out.println("You\'ve made " + count + " tries before successful guess");    
42
+    }
43
+
44
+    public static int GetAnInteger()
45
+    {
46
+        while (true)
47
+        {
48
+            try
49
+            {
50
+                return in.nextInt();
51
+            }
52
+            catch (InputMismatchException e)
53
+            {
54
+                in.next();
55
+                System.out.println("Invalid input! Try again!");
56
+            }
57
+        }
8 58
     }
9 59
 }

+ 12
- 0
README.TXT View 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:

BIN
main.class View File


+ 7
- 0
main.ctxt View File

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

+ 32
- 0
package.bluej View File

@@ -0,0 +1,32 @@
1
+#BlueJ package file
2
+editor.fx.0.height=0
3
+editor.fx.0.width=0
4
+editor.fx.0.x=0
5
+editor.fx.0.y=0
6
+objectbench.height=164
7
+objectbench.width=461
8
+package.divider.horizontal=0.6
9
+package.divider.vertical=0.6845018450184502
10
+package.editor.height=364
11
+package.editor.width=674
12
+package.editor.x=545
13
+package.editor.y=104
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