Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will begin by prompting the user to enter a number 0-2, 0 is for scissors , 1 is for rock , and 2 is


You will begin by prompting the user to enter a number 0-2, 0 is for scissors, 1 is for rock, and 2 is for paper, then let the computer randomly generate an integer from 0-2.

Input Data

A number between 0 and 2

Output Data

You won, the computer won, or it was a tie.


Sample Output

Enter 0 for scissors, 1 for rock, and 2 for paper: 1 The computer is Scissors, you are Rock, you won! >>

Enter 0 for scissors, 1 for rock, and 2 for paper: 2 The computer is Paper, you are Paper, it was a tie! >>

Enter 0 for scissors, 1 for rock, and 2 for paper: 0 The computer is Paper, you are Scissors, you won! >>


Requirements & Considerations

1. Output the strings for the corresponding input number and random number (If you use System.out.printf, the format for the strings would be %s) and whether you won, the computer won, or it was a tie.


Note:

1. To generate a random number in Java, you can use the Random class, but you

have to create a Random object just like you did for the Scanner class. And you have to import java.util.Random; at the beginning of your program.


(Example) Random rand = new Random(); int value = rand.nextInt(50); //generates integer from 0-49

What about from 1-50? int value = 1 + rand.nextInt(50); //generates integer from 1-50

2. Use one if statement to assign a value to my string (the input number), use another if statement to assign a value to the random string (the random number)

(Example) String myStr = " ";

if (myNum == 1)

myStr = "Rock"; ......

_ _

3. Use a third if statement to determine who won or it was a tie.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Certainly Heres a simple Java program that fulfills your requirements import javautilRandom import j... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Java Programming, Comprehensive Version

Authors: Y. Daniel Liang

10th Edition

133761312, 978-0133761313

More Books

Students also viewed these Programming questions