#31 finished lab - guessing game

Открыто
christiansheridan хочет смерджить 1 коммит(ов) из christiansheridan/TooLargeTooSmall:master в master
6 измененных файлов: 87 добавлений и 0 удалений
  1. Двоичные данные
      .DS_Store
  2. Двоичные данные
      TooLarge/Main.class
  3. 5
    0
      TooLarge/Main.ctxt
  4. 38
    0
      TooLarge/Main.java
  5. 12
    0
      TooLarge/README.TXT
  6. 32
    0
      TooLarge/package.bluej

Двоичные данные
.DS_Store Просмотреть файл


Двоичные данные
TooLarge/Main.class Просмотреть файл


+ 5
- 0
TooLarge/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

+ 38
- 0
TooLarge/Main.java Просмотреть файл

@@ -0,0 +1,38 @@
1
+
2
+/**
3
+ * Guessing game: TooLargeTooSmall.
4
+ *
5
+ * @author (Chistian)
6
+ * @version (version1 10-19-18)
7
+ */
8
+import java.util.*;
9
+import java.util.Scanner;
10
+public class Main {
11
+
12
+    public static void main(String[] args){
13
+        Random rand = new Random();
14
+        int n = rand.nextInt(10) + 1;
15
+        Scanner in = new Scanner(System.in);
16
+        System.out.println("Please guess a number between 1 and 10");
17
+        int guess = in.nextInt();
18
+        int lastGuess = 0;
19
+        int numberOfGuesses=1;
20
+        while (n != guess){
21
+            if (n < guess) {
22
+                System.out.println("too large, guess another number");
23
+                if (guess != lastGuess){
24
+                    lastGuess = guess;
25
+                    numberOfGuesses++;}
26
+            }
27
+            else if(n > guess) {
28
+                System.out.println("too small, guess another number");
29
+                if (guess != lastGuess){
30
+                    lastGuess = guess;
31
+                    numberOfGuesses++;}
32
+
33
+            } 
34
+            guess = in.nextInt();
35
+        }
36
+        System.out.println("correct! you took " +String.format("%d",numberOfGuesses)+ " guesses to get it right");
37
+    }
38
+}

+ 12
- 0
TooLarge/README.TXT Просмотреть файл

@@ -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
TooLarge/package.bluej Просмотреть файл

@@ -0,0 +1,32 @@
1
+#BlueJ package file
2
+editor.fx.0.height=722
3
+editor.fx.0.width=800
4
+editor.fx.0.x=505
5
+editor.fx.0.y=83
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=131
13
+package.editor.y=156
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=140
31
+target1.x=70
32
+target1.y=10