Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Project 1: Rock, Paper, Scissor (Courtesy Phillip Witkin) Use 0 means rock, l me

ID: 3811846 • Letter: P

Question

Project 1: Rock, Paper, Scissor (Courtesy Phillip Witkin) Use 0 means rock, l means paper, 2 means scissor. We use integers to represent these options since it is easy for computer to generate a random integer and that is the only way we learn now. 2. Computer generates a random integer 0,1, or 2. 3. You enter from console an integer 0, 1, 2. (Can you guarantee that you can only enter 0,1,2, if you enter any other integer, the system will force you to re- enter until one of 0, 1, 2 is entered). 4. Report the result. For example, Enter 0 for rock, 1 for paper, 2 or scissor: l (return key) Computer enters rock. User enters paper. User wins. 5. See the way I label those options: rock

Explanation / Answer

import java.util.Scanner; import java.util.Random; public class rps { public static void main (String args[]){ int input; int b = 1; Scanner sage = new Scanner(System.in); Random rnd = new Random(); System.out.println("Rock Paper Scissors, by Sage!"); System.out.println("Select 1, 2, 3, for Rock, Paper, Scissors"); //Menu Present, pretty bad still while (b != 0){ int rock = 1, paper = 2, scissors = 3; input = sage.nextInt(); int randomNumber = rnd.nextInt(3-1+1)+1; if(randomNumber == rock){ if(input == rock){ System.out.println("Rock vs. Rock, ITS A TIE!"); } else if(input == paper){ System.out.println("Rock vs. Paper! You win!" ); } else if(input == scissors){ System.out.println("Rock vs. Scissors! You lose!"); } //These blocks establish options if the computer got Rock else if(randomNumber == paper){ if(input == rock){ System.out.println("Paper vs. Rock! You lose!"); } else if(input == scissors){ System.out.println("Paper vs. Scissors! You win!"); } else if(input == paper){ System.out.println("Paper vs. Paper! Its a tie!"); } //These blocks establish the options if comp. got paper else if(randomNumber == scissors){ if(input == rock){ System.out.println("Scissors vs. Rock! You win!"); } else if(input == scissors){ System.out.println("Scissors vs. Scissors, ITS A TIE!"); } else if(input == paper){ System.out.println("Scissors vs Paper! You lose!"); } //These blocks establish if the computer got scissors. } } } } } }