forked from Ishaan28malik/Hacktoberfest-2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
guessergame.java
104 lines (83 loc) · 2.13 KB
/
guessergame.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package GameProject;
import java.util.Scanner;
class guesser{
int guessNum;
public int guessingNum()
{
Scanner Scan=new Scanner(System.in);
System.out.println("Guesser please guess the number:");
guessNum=Scan.nextInt();
return guessNum;
}
}
class player{
int guessNum;
public int guessingNum(){
Scanner Scan=new Scanner(System.in);
System.out.println("Player! Guess the no.:");
guessNum=Scan.nextInt();
return guessNum;
}
}
class umpire{
int numFromGuesser;
int numFromPlayer1;
int numFromPlayer2;
int numFromPlayer3;
void collectNumFromGuesser()
{
guesser obj=new guesser();
numFromGuesser=obj.guessingNum();
}
void collectNumFromPlayer()
{
player P1=new player();
player P2=new player();
player P3=new player();
numFromPlayer1=P1.guessingNum();
numFromPlayer2=P2.guessingNum();
numFromPlayer3=P3.guessingNum();
}
void compare()
{if(numFromGuesser==numFromPlayer1)
{
if(numFromGuesser==numFromPlayer2 && numFromGuesser==numFromPlayer3){
System.out.println("All Guesses the no. correct");
}
else if(numFromGuesser==numFromPlayer2){
System.out.println("Player 1&2 are WINNER ");
}
else if(numFromGuesser==numFromPlayer3){
System.out.println("Player 1&3 are WINNER ");
}else{
System.out.println("Player1 has one the game");
}
}
else if(numFromGuesser==numFromPlayer2)
{
if(numFromPlayer2==numFromPlayer3)
{
System.out.println("Player 2 and player 3 has one game");
}
else {
System.out.println("Player2 has one the game");
}
}
else if(numFromGuesser==numFromPlayer3)
{
System.out.println("Player3 has one the game");
}
else{
System.out.println("Sorry! No One Is WINNER");
}
}
}
class guessgame{
public static void main(String[] args) {
System.out.println("Game Started");
umpire u=new umpire();
u.collectNumFromGuesser();
u.collectNumFromPlayer();
u.compare();
}
}