Instantly share code, notes, and snippets.

Embed
What would you like to do?
CSC-111 HW3 Rock Paper Scissors
/*
* Tony Silvestri
* 10/01/2018
* CSCI-111
* Problem 3.17 on P 124
* Implements Rock, Paper, Scissors Game Logic
*/
import java.util.Scanner;
public class RockPaperScissors {
public static void main(String[] args) {
final String TITLE = "Rock, Paper, Scissors Game V2.0";
final int ROCK = 0;
final int PAPER = 1;
final int SCISSORS = 2;
Scanner input = new Scanner(System.in);
System.out.println("Welcome to " + TITLE + "\n");
System.out.print("It's your throw.\n" + "Enter [0] for ROCK, [1] for PAPER or [2] for SCISSORS ");
int player = input.nextInt();
input.close();
if (player < 0)
System.out.println("Invalid number, Please enter one of the following: 0,1,2");
else if (player > 2)
System.out.println("Invalid number, Please enter one of the following: 0,1,2");
else {
int computer = (int) (Math.random() * 3);
if (player == computer) {
System.out.print("TIE. You both threw: ");
if (player == ROCK)
System.out.println("ROCK.");
else if (player == PAPER)
System.out.println("PAPER.");
else
System.out.println("SCISSORS.");
} else if (computer == ROCK) {
if (player == PAPER)
System.out.println("You WIN!!! Your PAPER covers Computer's ROCK.");
else
System.out.println("You LOSE!!! Computer's ROCK smashes Your SCISSORS.");
} else if (computer == PAPER) {
if (player == SCISSORS)
System.out.println("You WIN!!! Your SCISSORS cuts Computer's PAPER.");
else
System.out.println("You LOSE!!! Computer's PAPER covers Your ROCK.");
} else {
if (player == ROCK)
System.out.println("You WIN!!! Your ROCK smashes Computers SCISSORS.");
else
System.out.println("You LOSE!! Computer's SCISSORS cuts Your PAPER.");
}
}
System.out.println("\nThank you for playing " + TITLE + "\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment