Question
Write a JAVA program to simulate the game of paper-rock-scissors. The computer will play against a human user of your program. This program will use
Write a JAVA program to simulate the game of paper-rock-scissors.
The computer will play against a human user of your program. This program will use no psychology or artificial intelligence.
The number of hands in a round is determined by user (player). This must be an odd integer, to ensure there will be a winner.
The computer will make its choice of paper p, rock r or scissors s by generating a random number of 0, 1, or 2.
Write the program in this order:
First:
Write a function that prompts the user to enter the odd number of hands for the round.
Second:
Write a function that will read in the user choice of p, r or s. This function needs NO incoming parameters and returns a char, the users choice. The function will use a do while loop that does not exit until the user enters in a valid choice.
Compile this
Third:
Write a function that generates the computer move. This function has NO parameters and returns the random computer choice. Generate a random number from 0 to 2.
If the number is 0, the computer move to return is p, if the number is 1, the computer move to return is r if the number is 2, the computer move to return is s.
Compile this code . It will not run since you have not written main( ) yet.
Fourth:
Write a function that takes in two parameters, the human move (eitherp, r or s) and the computer move. This function will compare the human move to the computer move and determine which won the hand.
paper beats rock
rock beats scissors
scissors beat paper
a tie is if neither wins (they both have the same choice)
Compile this code Program will not run since you have not written main( ) yet.
Fifth:
Write main( ) using the pseuducode given below. Once this compiles, you can compile run and test the entire program.
All documentation standards apply.
Pseudocode for main( )
Declare all the variables used in main
//numberOfHands, playAgain, humanHandWinCount, computerHandWinCount, humanMove, computerMove, whoWonHand, winFlag, totalGamesWonbyHuman, totalGamesWonByComptuer
set TotalGamesWonbyHuman to 0 set totalGamesWonByComputer to 0
while the human wants to play another game
call function to determine how many hands in the game (must be an odd integer)
set humanHand Win count to 0
set computeHandWin count to 0
set win flag to false
while there is no winner
get the computer choice and assign to the variable in main by calling a function read the human choice and assign to the variable in main by calling a function print both the human and computer choices determine who won this hand by calling a function
if the human won print human won the hand message increment human win count else if the computer won the hand print the computer won the hand message increment computer win count else print the hand was a tie
if either human wins or computer wins equals numberOfHands/2 + 1 set win flag to true end of no winner loop
if human wins equals numberOfHands/2 + 1 print human won the round else print the computer won the round
ask the user if he/she wants another round (game) read users response end of user wants to play loop
print total games won by human print total games won by computer
print a good-bye message
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