/* CS 111A - Craig Persiko - Lab2.java
Paper-rock-scissors - Programming Lab 2 Solution for regular credit
This program scores the paper-rock-scissors game.
*/
import java.util.Scanner;
class Lab2
{
public static void main(String[] args)
{
Scanner inputBuffer = new Scanner(System.in);
String input;
char play1, play2;
System.out.println("Welcome to Craig's Rock-Paper-Scissors Game");
System.out.print("Player One, please enter your move: ");
input = inputBuffer.nextLine();
play1 = input.charAt(0);
System.out.print("Player Two, please enter your move: ");
input = inputBuffer.nextLine();
play2 = input.charAt(0);
switch (play1)
{
case 'p':
case 'P':
switch (play2)
{
case 'p':
case 'P':
System.out.println("Tie with Paper!");
break;
case 'r':
case 'R':
System.out.println("Player One wins: Paper covers Rock!");
break;
case 's':
case 'S':
System.out.println("Player Two wins: Scissors cut Paper!");
break;
default:
System.out.println("Player Two has entered an invalid move");
}//end of switch for player two.
break;
case 'r':
case 'R':
play2 = Character.toLowerCase(play2);
switch (play2)
{
case 'p':
System.out.println("Player Two wins: Paper covers Rock!");
break;
case 'r':
System.out.println("Tie with Rock!");
break;
case 's':
System.out.println("Player One wins: Rock breaks Scissors!");
break;
default:
System.out.println("Player Two has entered an invalid move");
}
break;
case 's':
case 'S':
if(play2 == 'p' || play2 == 'P')
{
System.out.println("Player One wins: Scissors cut Paper!");
}
else if(play2 == 'r' || play2 == 'R')
{
System.out.println("Player Two wins: Rock breaks Scissors!");
}
else if(play2 == 's' || play2 == 'S')
System.out.println("Tie with Scissors!");
else
System.out.println("Player Two has entered an invalid move");
break;
default:
System.out.println("Player One has entered an invalid move");
}//End of switch for Player One.
}
}
/* Sample Output:
Welcome to Craig's Rock-Paper-Scissors Game
Player One, please enter your move: rock
Player Two, please enter your move: Paper
Player Two wins: Paper covers Rock!
Welcome to Craig's Rock-Paper-Scissors Game
Player One, please enter your move: scissors
Player Two, please enter your move: w
Player Two has entered an invalid move
Welcome to Craig's Rock-Paper-Scissors Game
Player One, please enter your move: air
Player Two, please enter your move: paper
Player One has entered an invalid move
Welcome to Craig's Rock-Paper-Scissors Game
Player One, please enter your move: S
Player Two, please enter your move: P
Player One wins: Scissors cut Paper!
Welcome to Craig's Rock-Paper-Scissors Game
Player One, please enter your move: rock
Player Two, please enter your move: Rock
Tie with Rock!
*/
syntax highlighted by Code2HTML, v. 0.9