-
Notifications
You must be signed in to change notification settings - Fork 0
/
RockScissorPaper.java
58 lines (49 loc) · 2.05 KB
/
RockScissorPaper.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
package com.company;
import java.util.Random;
import java.util.Scanner;
public class CWH_20_RockScissorPaperGame {
public static void main(String[] args) {
Random r = new Random();
Scanner sc = new Scanner(System.in);
int tie = 0, You_win = 0, You_Lose = 0, n = 5, invalid_choice = 0;
System.out.println("Please Enter Your Choice");
System.out.println("Press '0' for Rock\nPress '1' for Scissor\nPress '2' for Paper");
while (n > 0) {
int UserChoice = sc.nextInt();
int ComputerChoice = r.nextInt(3);
if (UserChoice == ComputerChoice) {
System.out.println("This is a TIE\n");
tie += 1;
} else if (ComputerChoice == 0 && UserChoice == 1) {
System.out.println("You Lose\n");
You_Lose += 1;
} else if (ComputerChoice == 1 && UserChoice == 0) {
System.out.println("You Win\n");
You_win += 1;
} else if (ComputerChoice == 0 && UserChoice == 2) {
System.out.println("You Win\n");
You_win += 1;
} else if (ComputerChoice == 2 && UserChoice == 0) {
System.out.println("You Lose\n");
You_Lose += 1;
} else if (ComputerChoice == 1 && UserChoice == 2) {
System.out.println("You Lose\n");
You_Lose += 1;
} else if (ComputerChoice == 2 && UserChoice == 1) {
System.out.println("You Win\n");
You_win += 1;
} else {
invalid_choice+=1;
System.out.println("Invalid Choice");
if (invalid_choice >=2){
System.out.println("You Choose Invalid option "+ invalid_choice+"times");
break;
}
}
n-=1;
}
System.out.println("You Win " + You_win + " times");
System.out.println("You Lose " + You_Lose + " times");
System.out.println("Tie " + tie +" times");
}
}