Here is my code:
import java.util.*;
class rps{
public static void main(String args[]){
Random number = new Random();
Scanner input = new Scanner(System.in);
// player chooses
String choice;
System.out.println("Enter your throw (rock, paper, scissors)(enter exactly as shown): ");
choice = input.nextLine();
System.out.println("The player throws "+choice);
// computer chooses
int integer;
String computerinput;
integer = 1+number.nextInt(3);
if(integer == 1){
computerinput = "rock";
}else if(integer == 2){
computerinput = "paper";
}else{
computerinput = "scissors";
}
String message = "The computer throws "+ computerinput;
System.out.println(message);
// determining winner...
boolean isTie = computerinput.equals(choice);
boolean isWin = (computerinput.equals("rock") && choice.equals("scissor")) ||
(computerinput.equals("paper") && choice.equals("rock")) ||
(computerinput.equals("scissor") && choice.equals("paper"));
//message
if (isWin){
message += ". Computer Won.";
}else if (isTie){
message += " too. It is a Tie";
}else{
message += ". You Won";
}
System.out.print("\n"+message);
}
}
Output:
Enter your throw (rock, paper, scissors)(enter exactly as shown):
paper
The player throws paper
The computer throws scissors
The computer throws scissors. You Won
It should have said "Computer won." not "You won".