Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program: Rock-Paper-Scissors Game Description: The popular rock-paper-scissors game is usually played between two people in which each player simultaneously chooses either a rock or a

Program: Rock-Paper-Scissors Game Description: The popular rock-paper-scissors game is usually played between two people in which each player simultaneously chooses either a rock or a paper or a scissor (usually with an outstretched hand). The rule of the game is simple: rock crushes scissor, scissor cuts paper, and paper wraps rock. If both the players choose the same object, then it ends in a tie. (See this link for more details.) Problem Description: You have to play the rock-paper-scissor game against the computer for 1000 times. You receive the following rewards each time you play the game:

You get $2 if you win

You get $1 if there is a tie

You get $0 if you lose

The computer randomly chooses rock, paper, or scissor in each game. Rather than deciding what to play (rock, paper or scissor) for each individual game, you decide to use the following strategy:

Play rock for games 1-300

Play scissor for games 301-600

Play paper for games 601-1000

Write a program to play the rock-paper-scissors game against the computer for 1000 times using the above strategy. You are required to calculate the total reward that you accumulate after playing the game 1000 times.

Use loops to simulate the game 1000 times. In each iteration, generate a random integer 1, 2, or 3 representing rock, paper, and scissor, respectively and use that number to know what computer has played. Using your strategy described above, figure out whether you win, lose or tie the game in each iteration. Maintain a variable to keep a track of the amount that you have won and keep updating that amount in each iteration depending on the result of the game. You can generate a random integer 1, 2, or 3 as follows:

int randomNum = 1 + (int)(3*Math.random( ));

***Also, please display code using Java

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

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

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions

Question

Evaluate 3x - x for x = -2 Answer:

Answered: 1 week ago

Question

What is group replacement? Explain with an example. (2-3 lines)

Answered: 1 week ago