-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRockPaperScissors.java
More file actions
71 lines (67 loc) · 1.73 KB
/
RockPaperScissors.java
File metadata and controls
71 lines (67 loc) · 1.73 KB
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
import java.lang.Math;
import java.util.Scanner;
public class RockPaperScissors
{
public static void main(String[] args)
{
String computerMove = ComputerMove();
String playerMove = PlayerMove();
CheckMoves(computerMove, playerMove);
}
private static String ComputerMove()
{
int i = ((int) (Math.random() * 3));
String compMove = "";
switch (i)
{
case 0:
compMove = "Rock";
break;
case 1:
compMove = "Paper";
break;
case 2:
compMove = "Scissors";
break;
}
return compMove.toLowerCase();
}
private static String PlayerMove()
{
Scanner sc = new Scanner(System.in);
String pMove = sc.nextLine();
pMove = pMove.toLowerCase();
return pMove;
}
private static void CheckMoves(String cMove, String pMove)
{
if(cMove.equals(pMove))
{
System.out.println("Tie!");
}
else if (cMove == "rock" && pMove == "paper")
{
System.out.println("You Win!");
}
else if (cMove == "paper" && pMove == "rock")
{
System.out.println("Computer Wins!");
}
else if (cMove == "scissors" && pMove == "paper")
{
System.out.println("Computer Wins!");
}
else if (cMove == "paper" && pMove == "scissors")
{
System.out.println("You Win!");
}
else if (cMove == "rock" && pMove == "scissors")
{
System.out.println("Computer Wins!");
}
else if (cMove == "scissors" && pMove == "rock")
{
System.out.println("You Win!");
}
}
}