forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumber_Gusses.java
55 lines (49 loc) · 1.46 KB
/
Number_Gusses.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.company;
import java.util.Random;
import java.util.Scanner;
class Game{
public int Computer_input;
public int User_input;
//public int noOfGuesses;
// public int getNoOfGuesses() {
// return noOfGuesses;
// }
//public void setNoOfGuesses(int noOfGuesses) {
// this.noOfGuesses = noOfGuesses;
// }
public Game() {
Random rand=new Random();
Computer_input = rand.nextInt(100);
}
//method for taking input from user
public void takeUserInput(){
Scanner input=new Scanner(System.in);
System.out.println("Enter the Number That you want to guess it :");
User_input=input.nextInt();
input.close(); //input closed
}
boolean isCorrectNumber(){
if(User_input==Computer_input){
System.out.println("Congrats!!!You guess the Correct number..");
return true;
}
else if(User_input<Computer_input){
System.out.println("Your number is less than the computer number...");
}
else if (User_input>Computer_input){
System.out.println("Your number is greater than the computer number ...");
}
return false;
}
}
public class Number_Gusses {
public static void main(String[] args) {
Game g=new Game();
boolean b=false;
while(!b){
g.takeUserInput();
b= g.isCorrectNumber();
System.out.println(b);
}
}
}