-
-
Save bytecodeman/a094e286c9d40f3fbc9f62c85547b297 to your computer and use it in GitHub Desktop.
CSC-111 HW3 Rock Paper Scissors using an OR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Tony Silvestri | |
* 10/1/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 V1.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 || player > SCISSORS) { | |
System.out.println("You LOSE!!! You can't follow simple entry instructions."); | |
} 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