-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRockPaperScissors.java
112 lines (99 loc) · 3.54 KB
/
RockPaperScissors.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
103
104
105
106
107
108
109
110
111
112
/*
* Rock, Papers and Scissors
* Prajeet Bohara
* 12/19/2023
*/
import java.util.*;
public class RockPaperScissors {
public static void main(String[] args) {
Scanner inscan = new Scanner(System.in);
System.out.println("Let's Play Rock, Papers, Scissors.");
System.out.println("When I say 'shoot', Choose: rock, paper, or scissors.");
System.out.println("Are you ready? Write 'yes' if you are.");
String response = inscan.nextLine();
if(response.equals("yes")){
for (int dex = 0; dex < 3; dex ++){
String human1 = humanChoice();
System.out.println("You choose "+ human1);
String comp1 = compChoice();
System.out.println("The computer choose "+ comp1);
String result = score(human1, comp1);
System.out.println(result);
int humanLeaderboard = HumanPoints(result);
int compLeaderboard = compPoints(result);
System.out.println("Your score is "+ humanLeaderboard
+"Computer score is "+ compLeaderboard);
}
}
else{
System.out.println("Aight!, see ya next time boi!");
}
}
public static String humanChoice(){
Scanner scan = new Scanner(System.in);
System.out.println("Great!"
+ "rock-paper-scissors, shoot!");
String human = scan.nextLine();
return human;
}
public static String compChoice(){
Random rand = new Random();
int num = rand.nextInt(2);
switch(num){
case 0:
return "rock";
case 1:
return "paper";
case 2:
return "scissors";
default:
return "invalid";
}
}
public static String score(String human1, String comp1){
if ((human1.equals("paper")&& comp1.equals("rock"))|| (human1.equals("rock") && comp1.equals("scissors")) || (human1.equals("scissors")&& comp1.equals("paper"))){
return "You Win";
}
else if ((comp1.equals("rock")&& human1.equals("scissors"))|| (comp1.equals("paper")&& human1.equals("rock"))|| (comp1.equals("scissors")&& human1.equals("paper"))){
return "you lose";
}
else if ((comp1.equals(human1))){
return "Its a tie";
}
else{
return "something is invalid";
}
}
public static int HumanPoints(String result){
int humanScore = 0;
switch (result){
case "You Win":
humanScore += 1;
return humanScore;
case "you lose":
humanScore = 0;
return humanScore;
case "Its a tie":
humanScore += 1;
return humanScore;
default :
return 0;
}
}
public static int compPoints(String result){
int compScore = 0;
switch (result){
case "You Win":
compScore = 0;
return compScore;
case "you lose":
compScore += 1;
return compScore;
case "Its a tie":
compScore += 1;
return compScore;
default:
return 0;
}
}
}