1 import java.io.*;
2
3 public class NewMain10 {
4
5 static String userChoiceWord, compChoiceWord;
6 static int tie, win, loss;
7 static int userChoice, compChoice;
8 static int randNum;
9
10 public static void main (String args []) throws IOException
11 {
12 BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
13
14 int playAgain;
15 playAgain=1;
16 userChoiceWord="0";
17 compChoiceWord="0";
18
19
20 System.out.println("ROCK PAPER SCISSORS");
21 System.out.println("===================");
22
23 do{
24 System.out.println();
25 System.out.println("1=Rock");
26 System.out.println("2=Paper");
27 System.out.println("3=Scissors");
28 System.out.println("===========");
29 System.out.println("Choose:");
30 userChoice = Integer.parseInt(br.readLine());
31 System.out.println();
32
33 if(userChoice==1){
34 userChoiceWord=("Rock.");}
35 if(userChoice==2){
36 userChoiceWord=("Paper.");}
37 if(userChoice==3){
38 userChoiceWord=("Scissors.");}
39
40 compChoice=randomWholeNumber(randNum);
41
42 if(compChoice==1){
43 compChoiceWord=("Rock.");}
44 if(compChoice==2){
45 compChoiceWord=("Paper.");}
46 if(compChoice==3){
47 compChoiceWord=("Scissors.");}
48
49 System.out.println("You have chosen "+userChoiceWord);
50 System.out.println("The computer has chosen "+compChoiceWord);
51
52 if(userChoice==compChoice){
53 tie=tie+1;}
54 if(((userChoice==1)&&(compChoice==2))||((userChoice==2)&&(compChoice==3))||((userChoice==3)&&(compChoice==1))){
55 loss=loss+1;}
56 if(((userChoice==1)&&(compChoice==3))||((userChoice==2)&&(compChoice==1))||((userChoice==3)&&(compChoice==2))){
57 win=win+1;}
58
59 System.out.println();
60 System.out.println(determineOutcome(tie, loss, win, userChoice, compChoice));
61
62 System.out.println();
63 System.out.println("WINS: "+win);
64 System.out.println("LOSSES: "+loss);
65 System.out.println("TIES: "+tie);
66 System.out.println();
67 System.out.println("Press 1 to play again.");
68 playAgain=Integer.parseInt(br.readLine());
69
70 }while(playAgain==1);
71
72 }
73
74
75 public static int randomWholeNumber(int randNum){
76
77 randNum = (int) ((Math.random()*3)+1);
78 return (randNum);
79
80 }
81
82 public static String determineOutcome(int tie, int loss, int win, int userChoice, int compChoice){
83
84 if(userChoice==compChoice)
85 {
86 return "YOU'VE TIED";
87 }
88
89 if(((userChoice==1)&&(compChoice==2))||((userChoice==2)&&(compChoice==3))||((userChoice==3)&&(compChoice==1))){
90 return "YOU LOSE";
91 }
92
93 if(((userChoice==1)&&(compChoice==3))||((userChoice==2)&&(compChoice==1))||((userChoice==3)&&(compChoice==2))){
94 return "YOU WIN";
95 }
96
97 else{
98 return "error";}
99
100 }
101
102 }
103