Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Scissors-Rock-Paper (SRP) Game: When we were children, many of us played this game in which two players simultaneously display a hand in one of three

Scissors-Rock-Paper (SRP) Game:

When we were children, many of us played this game in which two players simultaneously display a hand in one of three configurations. A flat hand represents paper, a fist represents a rock, and an extended index and middle finger stand for a pair of scissors. The outcome of the game is determined by the following rule:

-Scissors cut PaperScissors wins

-Paper wraps RockPaper wins

-Rock breaks ScissorsRock wins

In this question, you need to write a Java programto simulate SRP game.

Part(A)

Include following methods to your program.

- findRandom-This method takes in no input parameter and returns a random integer between -3. Statement to generate random numbers between a-b:

int x = (int) (Math.random()*(b-a+1)) + a

Here, a ? x ? b. (a, b are inclusive to the possible value range)

- numbersToSign- This method takes in an integer parameter which can be any number from 1 to 3 and returns a String corresponding to the number. The String for each numberis as follows. (Assume that the input is always a 1-3 integer.)

image text in transcribed

Part(B):

Within the main method do the following:

1)Declare two integer variables (Say r1 and r2). Initialize them to zero.

2)Declare two string variables (Say s1 and s2). Initialize them to empty string.

3)Use do-while loop as

do{

/*

a)Assign new values to r1 by calling the findRandom method.

b)Assign new values to r2 by calling the findRandom method.

c)Assign new value to s1 by calling numbersToSign method by passing r1.

d)Assign new value to s2 by calling numbersToSign method by passing r2.

*/

/*Display the value of s1 and s2 to user as player 1 and player2 hands.*/

System.out.println(Player 1 hand:+ s1);

System.out.println(Player 2 hand:+ s2);

} while (//e)s1 is equal to s2);

Once the program exit from the above loop displays the winner based on following conditions.

image text in transcribed

The output of your program may look like as follows . (Note that this program does not take any user input).

image text in transcribed

Problem 2:

Write a Java program that takes 5 words from the user and store them in a string array. Next, print the 2 lines of output containing, All words in reverse order (Last word to the first word). Every word at an even index of the array. (That is, words at index 0, 2 &4)

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

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions