forked from riya2001-cloud/java-hacktober
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStonePaperScissor.java
90 lines (85 loc) · 3.2 KB
/
StonePaperScissor.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
import java.util.Random;
import java.util.Scanner;
public class StonePaperScissor {
public static void main(String[] args){
String logo = """
______ ______ ______
/ ___/ | __ \\ / ___/
| (__ | |__) | | (__
\\__ \\ | ___/ \\__ \\
___) | _ | | _ ___) | _
/_____/ |_| |__| |_| /_____/ |_|
""";
System.out.println(logo);
System.out.println("Welcome to Stone Paper Scissor!");
System.out.println("\n Instructions: \n\t There will be 10 matches to be played");
Game();
}
public static void Game(){
int userscore = 0;
int compscore = 0;
String winner = "";
int a = 1;
while (a <= 10) {
System.out.println("""
________________________________________________________
""");
System.out.println("\n \t\tMatch : "+a+"\n");
Scanner scan = new Scanner(System.in);
System.out.println("Enter either 'Stone / Paper / Scissor' : ");
String user = scan.next();
Random random = new Random(100);
int computer = random.nextInt();
String comp = "";
if (computer <= 33) {
comp = "Stone";
}
if (computer > 33 && computer <= 66){
comp = "Paper";
}
if (computer > 66 && computer <= 100){
comp = "Scissor";
}
System.out.println("Computer's choice : "+comp);
System.out.println("User's choice : "+ user);
// Computer
if (comp.equals("Stone") && user.equals("Scissor")|| user.equals("scissor")){
compscore = compscore+1;
}
if (comp.equals("Paper") && user.equals("Stone")|| user.equals("stone")){
compscore = compscore+1;
}
if (comp.equals("Scissor")&& user.equals("Paper") || user.equals("paper")){
compscore = compscore+1;
}
// User
if (user.equals("Stone")||user.equals("stone") && comp.equals("Scissor")){
userscore = userscore+1;
}
if (user.equals("Paper")||user.equals("paper") && comp.equals("Stone")){
userscore = userscore+1;
}
if (user.equals("Scissor")|| user.equals("scissor") && comp.equals("Papar")){
userscore = userscore+1;
}
System.out.println("User Score : "+userscore);
System.out.println("Computer : "+compscore);
if (compscore<userscore){
winner="User";
System.out.println("\tLead : "+winner+"\n");
}
if (userscore<compscore){
winner="Computer";
System.out.println("\tLead : "+winner+"\n");
}
if (userscore==compscore){
winner="Both";
System.out.println("\tLead : "+winner+"\n");
}
if (a==10){
System.out.println("\n\tGame won by "+winner);
}
a = a+1;
}
}
}