Question
This week, you will be writing a Java application program that plays the game of Paper, Rock, Scissors with the user. Your program will begin
This week, you will be writing a Java application program that plays the game of "Paper, Rock, Scissors" with the user.
Your program will begin by displaying the title of the game, and asking the user if instructions are needed. Next, the user will be asked to type in their choice. You should expect the user to type the word "paper", the word "rock", or the word "scissors".
After the user enters a choice, the computer will randomly pick one of the three words.
Next, display both the player's choice and the computer's choice to the screen, along with a message stating "I WIN" or "YOU WIN" or "IT'S A TIE".
Finally, the user will be asked if he/she wants to play again. If the user answers "Y" or "y", then the game will start again, by asking the user for another choice.
If the user does not want to play again, you some statistics about the game play will be displayed on the screen:
assignment part 1
There is already an existing class called PRS, with an existing main method.
Inside the PRS class, create a void method called instructions. The purpose of this method is to print the instructions on the screen to the user.
Do not change any of the existing code in the main method, and do not add code to the main method.
The following are the instructions that this method should print to the screen. Make sure that your formatting, and blank lines are exactly as shown below:
This is the popular game of paper, rock, scissors. Enter your choice by typing the word "paper", the word "rock" or the word "scissors". The computer will also make a choice from the three options. After you have entered your choice, the winner of the game will be determined according to the following rules: Paper wraps rock (paper wins) Rock breaks scissors (rock wins) Scissors cuts paper (scissors wins) If both you and the computer enter the same choice, then the game is tied.
assignment part 2
There is already an existing class called PRS, with no main method.
Inside the PRS class, create a method called analyzeRound. The purpose of this method is to analyze the user's choice and the computer's choice and determine who won.
The method should take two String parameters, in this order: the user's choice and the computer's choice. Both the user's choice and the computer's choice values are expected to be the word "paper", the word "rock", or the word "scissors".
The method should return a single integer as follows: Return the integer 1 if the player wins Return the integer 2 if the computer wins Return the number 3 if it is a tie
This method SHOULD NOT print the outcome on the screen.
Do not write or add a main method to this class. At this point, you are only creating the analyzeRound method.
Testing:
The name of each test will tell you what parameter values are being passed to your method.
If your method is not written correctly (i.e. does not have the correct parameters or return value data types), then the tests will fail and will show nothing.
If your code does not compile, then the tests will fail and will show nothing.
If your method is written correctly, but returns the wrong value, then the test will show failed, and will tell you what value the method should be returning.
If your method is written correctly and returns the correct value, then the test will pass
project part 1
getting started
Click the Open IDE button.
In the IDE window, look in the leftmost column and find the CSCI_1010 folder and inside it, find the project08 folder.
Open the Java file - PRS.java
the project
Create the entire paper, rock, scissors game program.
Note that this file already contains some starter code, and an existing method which will be explained below, under the technical notes section. DO NOT change any of the existing code or your program will fail the tests.
Begin by copying your instructions and analyzeRound methods from the assignment and pasting them into the PRS file, so you can use these two methods to help you complete the project.
Your program should begin by printing the title of game on the screen, followed by a line break.
The Game of Paper, Rock, Scissors
Next, you should ask the user if instructions are needed. If the user answers "Y" or "y", then you should display some basic instructions to the screen. Use your instructions method that you wrote for part 1 of the assignment to display the instructions on the screen.
Do you need instructions (Y or N)? Y This is the popular game of paper, rock, scissors. Enter your choice by typing the word "paper", the word "rock" or the word "scissors". The computer will also make a choice from the three options. After you have entered your choice, the winner of the game will be determined according to the following rules: Paper wraps rock (paper wins) Rock breaks scissors (rock wins) Scissors cuts paper (scissors wins) If both you and the computer enter the same choice, then the game is tied.
Next, you should ask the user to type in their choice. You should expect the user to type the word "paper", the word "rock", or the word "scissors". Don't worry about error checking at this time; you may assume that the user will enter one of these three words, however the user may enter any combination of upper and lowercase letters.
Enter your choice: rock
Next, you will need for the computer player to randomly pick one of the three words. You will use the methods shown in the notes below for this.
Use your analyzeRound method from part 2 of the assignment to analyze the player's choice and the user's choice and determine who won the game.
Next, display both the player's choice and the computer's choice to the screen, along with a message stating "I WIN" or "YOU WIN" or "IT'S A TIE".
You entered: rock Computer chose: scissors YOU WIN!
Next, youNext, you should ask the user if he/she wants to play again. If the user answers "Y" or "y", then you should loop back to asking the user to enter another choice.
Play again (Y or N)? N
If the user does not want to play again, you should display the following statistics to the screen:
Total number of games played Total number of wins for player Total number of wins for computer Total number of ties
Games played: 3 Wins for you: 1 Wins for me: 1 Tied games: 1
The following is an example of what your MIGHT see on the screen when your program runs. The exact output depends on what values that the user types in while the program runs. The user's inputted values are shown below in italics. Note that your program must display the exact formatting shown here - including the spaces and blank lines.
The Game of Paper, Rock, Scissors Do you need instructions (Y or N)? This is the popular game of paper, rock, scissors. Enter your choice by typing the word "paper", the word "rock" or the word "scissors". The computer will also make a choice from the three options. After you have entered your choice, the winner of the game will be determined according to the following rules: Paper wraps rock (paper wins) Rock breaks scissors (rock wins) Scissors cuts paper (scissors wins) If both you and the computer enter the same choice, then the game is tied. Enter your choice: rock You entered: rock Computer chose: scissors YOU WIN! Play again (Y or N)? Y Enter your choice: paper You entered: paper Computer chose: paper IT'S A TIE! Play again (Y or N)? Y Enter your choice: paper You entered: paper Computer chose: scissors I WIN! Play again (Y or N)? N Games played: 3 Wins for you: 1 Wins for me: 1 Tied games: 1
Technical Notes &aTechnical Notes & Requirements:
Use your instructions method from part 1 of the assignment to print the instructions on the screen to the user. The main program is not allowed to directly print the instructions to the screen. The main program must decide (based on the user's input) whether or not the instructions should be printed, and then call on the instructions method to display the instructions if necessary.
Use your analyzeRound method from part 2 of the assignment to analyze the player and computer choices, and determine who won the game. This method should be copied directly from part 2 of the assignment -- unchanged. Thus, this method SHOULD NOT be printing the outcome on the screen. This should be done in the main program.
The starter code already contains a method called computerChoose. The purpose of this method is to have the computer pick a choice from the three words, "paper", "rock" and "scissors". This method will cause the computer to randomly pick one of the choices, and it will return the choice back to your main program as a String. To use the method, you simply need to call on the method by name, and store it's return value in a variable.
Use the printf command to help you right-align the numbers when printing the final statistics. For example, System.out.printf("Tied games: %4d", 1); will cause the number "1" to be substituted wherever the % sign appears in the string. The "d" means to print the "1" as a normal decimal (integer) number. The "4" sets aside 4 spaces in which to print the "1" so that the "1" will appear right-aligned inside the block of 4 spaces.
Testing the program can be tricky since the whole purpose of a game is so that the user cannot predict the outcome of the game in advance. Because of this, the computerChoose method uses random numbers to make the game unpredictable. The problem with this, for program testing, is that if the game is unpredictable then it becomes difficult to reproduce problems when you discover an error during program testing. As such, when executing the program, you can add an extra "seed" number that can be used to start the random number generator. As long as the same seed number is used, then the computer will make the same choices in the same order, everytime the game is played - thus making it possible for you to predict the outcome of the game and so you will know whether the program is working correctly or not. Without the seed number, the computer chooses randomly and you won't know the outcome.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started