Question: In this problem you will create a computer game to play the game of Rock-Paper-Scissors with a user. > java RockPaperScissors Let's play! What's your

In this problem you will create a computer game to play the game of Rock-Paper-Scissors with a user.

> java RockPaperScissors

Let's play! What's your move? (r=rock, p=paper, s=scissors or q to quit)

r

I choose rock. It's a tie

Let's play! What's your move? (r=rock, p=paper, s=scissors or q to quit)

p

I choose paper. It's a tie

Let's play! What's your move? (r=rock, p=paper, s=scissors or q to quit)

g

That is not a valid move. Please try again.

(r=rock, p=paper, s=scissors or q to quit)

p

I choose rock. You win.

Let's play! What's your move? (r=rock, p=paper, s=scissors or q to quit)

s

I choose rock. I win!

Let's play! What's your move? (r=rock, p=paper, s=scissors or q to quit)

r

I choose rock. It's a tie

Let's play! What's your move? (r=rock, p=paper, s=scissors or q to quit)

s

I choose paper. You win.

Let's play! What's your move? (r=rock, p=paper, s=scissors or q to quit)

q

Thanks for playing!

Our most recent games (in reverse order) were:

Me: paper You: scissors

Me: rock You: rock

Me: rock You: scissors

Me: rock You: paper

Me: paper You: paper

Me: rock You: rock

Our overall stats are:

I won: 16% You won 33% We tied: 50%

Here are some detailed requirements of the game play and specifics about the program:

You will write your code in the main method, but you should use good style and helper functions as needed. Remember that these helper functions need to be static, because you are not creating any RockPaperScissors objects.

The game should repeat until the user enters q

The game should track the full move history for both players. It should store the move history of the user in an array of Strings and the move history of the system in a LinkedList of Strings. These variables are already set up in the starter code. You just need to use them.

The array that stores the users moves is initialized to size 5. As the user enters more moves than the array will hold you should write code to expand this array (really, to make a new array and copy over the contents of the old one). The new array should always be twice the size of the old array. E.g. on the 6th move, the array becomes size 10, on the 11th move it becomes size 20, etc.

At the end of the game, the system should print out up to the last 10 games, in reverse order. If there has not been 10 games, it should print out as many as has been played. If there have been more than 10 games, it should only print the most recent 10. (But remember, it should store the full game histories). It should also print the win and tie statistics as in the example.

Your program should gracefully handle incorrect input by re-prompting the user until they enter valid input. You can look for the letters r, s and p exactly, or allow more freedom in the input.

Your programs should generate no exceptions under (almost) any circumstances. Try to break with bad input.

Here is the code:

In this problem you will create a computer game to play the

import java.util.LinkedList; import java.util.Scanner; import java.util.Random; E public class RockPaperScissors public static void main( Stringt) args) int initialCapacity = 5; /I Store the user's move history string[] userMoves = new String[initialCapacity]; // Store the System' s move history LinkedList systemMoves-new LinkedList TODO: Write the code to play the game as specified by the writeup 7 TODO: When the game is done, write the code to print the move history // and stats //Initialize the quit command with character a //If user doesn't quit, go through the while loop while (quitcmd != 'g'){ system . out.print1n ("Let's play! What's your move? (r-rock, p-paper, s=scissors or q to quit)"); Ly

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!