//Ryan Giglio //rock paper scissors import java.util.Random; import cs1.Keyboard; import java.applet.Applet; import java.awt.*; public class RockPaperScissors { public static void main (String [] args) { Random generator = new Random(); int UserChoice, CompChoice; int Win = 0; int Lose = 0; int Tie = 0; char PlayAgain = 'y'; System.out.println ("Welcome to Ryan Giglio's boredom " + "rock paper scissors program!"); System.out.println (); System.out.println ("Instructions: Paper covers rock, " + "rock breaks scissors, and scissors cuts paper"); while (PlayAgain == 'y' || PlayAgain == 'Y') { CompChoice = Math.abs (generator.nextInt()) % 3 + 1; // Generates 1/2/3 System.out.println ("Make your selection"); System.out.println ("1: Rock"); System.out.println ("2: Paper"); System.out.println ("3: Scissors"); UserChoice = Keyboard.readInt(); if (CompChoice == 1) { if (UserChoice == 1) { System.out.println ("You picked: ROCK. The computer " + " picked: ROCK. It was a TIE!"); Tie++; } else if (UserChoice == 2) { System.out.println ("You picked: PAPER. The computer " + "picked: ROCK. You WIN!"); Win++; } else if (UserChoice == 3) { System.out.println ("You picked: SCISSORS. The computer " + "picked: ROCK. You LOSE!"); Lose++; } } if (CompChoice == 2) { if (UserChoice == 1) { System.out.println ("You picked: ROCK. The computer " + " picked: PAPER. You LOSE!"); Lose++; } else if (UserChoice == 2) { System.out.println ("You picked: PAPER. The computer " + "picked: PAPER. It was a TIE!"); Tie++; } else if (UserChoice == 3) { System.out.println ("You picked: SCISSORS. The computer " + "picked: PAPER. You WIN!"); Win++; } } if (CompChoice == 3) { if (UserChoice == 1) { System.out.println ("You picked: ROCK. The computer " + " picked: SCISSORS. You WIN!"); Win++; } else if (UserChoice == 2) { System.out.println ("You picked: PAPER. The computer " + "picked: SCISSORS. You LOSE!"); Lose++; } else if (UserChoice == 3) { System.out.println ("You picked: SCISSORS. The computer " + "picked: SCISSORS. It was a TIE!"); Tie++; } } System.out.println ("Would you like to play again? (y/n)"); PlayAgain = Keyboard.readChar(); } System.out.println("Thank you for playing!"); System.out.println("WINS: " + Win); System.out.println("LOSSES: " + Lose); System.out.println("TIES: " + Tie); } }