/* Susanne Wu
CS 111A
Programming Lab #2 : Rock - Paper - Scissors Game
RPS.java
Make a program that prompts two players in the game of rock-paper-scissors.
*/
import java.util.Scanner;
class RPS
{
public static void main(String[] args)
{
Scanner scan = new Scanner (System.in);
String P1, P2, R = "Rock", P = "Paper", S = "Scissors", I = "invalid move";
System.out.println("Welcome to the wonderful game of Rock-Paper-Scissors!");
System.out.println("Player One : rock, paper or scissors? ");
P1 = scan.nextLine();
P1 = P1.toLowerCase();
{
if(P1.equals("rock") || P1.equals("r"))
P1 = R;
else if(P1.equals("paper") || P1.equals("p"))
P1 = P;
else if(P1.equals("scissors") || P1.equals("s"))
P1 = S;
else
P1 = I;
}
System.out.println("Player Two : rock, paper, or scissors? ");
P2 = scan.nextLine();
P2 = P2.toLowerCase();
{
if(P2.equals("rock") || P2.equals("r"))
P2 = R;
else if(P2.equals("paper") || P2.equals("p"))
P2 = P;
else if(P2.equals("scissors") || P2.equals("s"))
P2 = S;
else
P2 = I;
}
if(P1.equals(R) && P2.equals(P))
System.out.println("Player Two wins : Paper covers Rock.");
else if(P1.equals(P) && P2.equals(S))
System.out.println("Player Two wins : Scissors cuts Paper.");
else if(P1.equals(S) && P2.equals(R))
System.out.println("Player Two wins : Rock beats Scissors.");
else if(P2.equals(R) && P1.equals(P))
System.out.println("Player One wins : Paper covers Rock.");
else if(P2.equals(P) && P1.equals(S))
System.out.println("Player One wins : Scissors cuts Paper.");
else if(P2.equals(S) && P1.equals(R))
System.out.println("Player One wins : Rock beats Scissors. ");
else if(P1.equals(P2))
System.out.println("Tied with " + P1 + ".");
else if(P1.equals(I))
System.out.println("Player One has made an " + P1 + ".");
else
System.out.println("Player Two has made an " + P2 + ".");
}
}
syntax highlighted by Code2HTML, v. 0.9