Sfoglia il codice sorgente

Determines if the number entered is too big or too small or correct

Akeem Cherry 6 anni fa
parent
commit
56154ba5ff

BIN
.DS_Store Vedi File


BIN
Too Large Too Small/Main.class Vedi File


+ 5
- 0
Too Large Too Small/Main.ctxt Vedi File

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

+ 57
- 0
Too Large Too Small/Main.java Vedi File

@@ -0,0 +1,57 @@
1
+
2
+/**
3
+ * Write a description of class Main here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+import java.util.Scanner;
9
+import java.util.*;
10
+public class Main
11
+{
12
+    
13
+    public static void main(String[] args){
14
+        int numOfGuesses = 1;
15
+        
16
+        Random randomNum = new Random();
17
+        int randNum = randomNum.nextInt(10)+1;
18
+        Scanner in = new Scanner(System.in);
19
+        System.out.print("Enter a number between 1 and 10 ");
20
+
21
+        int userNum = in.nextInt();
22
+        int newNum = 0;
23
+        while (userNum != randNum){
24
+            if (userNum > randNum){
25
+                System.out.print("Your number is TOO BIG! ");
26
+                if(userNum != newNum){
27
+                
28
+                //newNum = in.nextInt();
29
+                numOfGuesses++;
30
+            }
31
+            
32
+            userNum = in.nextInt();
33
+            }
34
+            else if(userNum < randNum){
35
+                System.out.print("Your number is TOO SMALL!  ");
36
+                if(userNum != newNum){
37
+                
38
+                //newNum = in.nextInt();
39
+                numOfGuesses++;
40
+            }
41
+            
42
+            userNum = in.nextInt();
43
+            
44
+        }
45
+        
46
+        }
47
+            System.out.println("Correct!");
48
+            System.out.println("It took " + numOfGuesses + "trys");
49
+            
50
+        
51
+    
52
+    
53
+        
54
+
55
+        
56
+    }
57
+}

+ 12
- 0
Too Large Too Small/README.TXT Vedi 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:

+ 32
- 0
Too Large Too Small/package.bluej Vedi File

@@ -0,0 +1,32 @@
1
+#BlueJ package file
2
+editor.fx.0.height=716
3
+editor.fx.0.width=800
4
+editor.fx.0.x=480
5
+editor.fx.0.y=24
6
+objectbench.height=101
7
+objectbench.width=776
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=196
13
+package.editor.y=60
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