Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in java RPS.java Load default template... m public class RPS { in public static void main(String[] args) { 9 } 20.5 a2, #2 Rock-paper-scissor Write

image text in transcribedimage text in transcribedin java

RPS.java Load default template... m public class RPS { in public static void main(String[] args) { 9 } 20.5 a2, #2 Rock-paper-scissor Write a program that allows a user to play a single game of rock-paper-scissor against the computer. Prompt the user to enter a random number seed and 'R', 'P', or 'S', then generate a random play for the computer, and finally announce the winner. When announcing the winner, be sure to state what the computer played, and the basis for winning: rock breaks scissors, paper covers rock, scissors cuts paper, or tie (nobody wins). Use a series of if-else statements to determine the winner. You should allow the user to enter lowercase or uppercase letters. If an invalid play is entered, print an error message and stop. To determine what the computer plays, generate a random number using the java.util.Random package and map these numbers to R-P-S. This will require creating a new instance of the Random class, setting the seed, and then calling the nextInt method: Random rndm = new Random(); rndm.setSeed (seed); // where 'seed' is the value you read from the input You may use the above code without attribution. See the documentation for Random.nextInt(). https://docs.oracle.com/javase/8/docs/api/java/util/Random.html. To get more practice with different branching constructs, use a switch statement to convert your random number to 'R', 'P', or 'S'. When the input field is: 200 R The output should be: Enter a seed number and R, P, or s: You entered: R The computer played: S You win! Rock breaks scissors

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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_2

Step: 3

blur-text-image_3

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

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions

Question

2. List the advantages of listening well

Answered: 1 week ago