subject

Write a program that lets the user play the game of rock, paper, scissors against the computer. the program should work as follows.

when the program begins, a random number in the range of 1 through 3 is generated. if the number is 1, then the computer has chosen rock. if the number is 2, then the computer has chosen paper. if the number is 3, then the computer has chosen scissors. don’t display the computer’s choice yet.

the user enters his or her choice of "rock", "paper", or "scissors" at the keyboard. 3. the computer’s choice is displayed.

a winner is selected according to the following rules:

• if one player chooses rock and the other player chooses scissors, then rock wins. the rock smashes the scissors.

• if one player chooses scissors and the other player chooses paper, then scissors wins. scissors cuts paper.

• if one player chooses paper and the other player chooses rock, then paper wins. paper wraps rock.

• if both players make the same choice, the game must be played again to determine the winner. be sure to divide the program into methods that perform each major task. here is the description of the methods you should implement:

• public static string computerchoice() – this method will return the computer’s choice of "rock", "paper", or "scissors". • public static string userchoice () – this method will return the user’s choice of "rock", "paper", or "scissors" after validating the user’s choice using isvalidchoice method.

• public static boolean isvalidchoice (string choice) – this method will take a string holding the user’s choice as parameter and return true if the choice is valid ("rock", "paper", or "scissors"), false otherwise. be sure that the comparison is not case sensitive.

• public static void determinewinner(string computer, string user)– this method will take both the choices as parameter and display the winner.

call the method isvalidchoice() in a while loop in the userchoice() method to verify that the choice that user enters must be "rock", "paper", or "scissors". if invalid string is input, isvalidchoice()will return false and the program should ask for new input until the valid input is given.

the user is allowed to play the game as often as desired .

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 21:30, mima851
Elements such as fonts colors visual structure graphics and the interface of a web page should complement each other to ensure blank
Answers: 3
image
Computers and Technology, 23.06.2019 00:30, devenybates
Which one of the following is the most accurate definition of technology? a electronic tools that improve functionality b electronic tools that provide entertainment or practical value c any type of tool that serves a practical function d any type of tool that enhances communication
Answers: 1
image
Computers and Technology, 23.06.2019 22:50, atifgujar
An environmental protection agency study of 12 automobiles revealed a correlation of 0.47 between engine size and emissions. at 0.01 significance level, can we conclude that there is a positive association between the variables? what is the p value? interpret.
Answers: 2
image
Computers and Technology, 23.06.2019 23:40, dudedude1593
Which of the following calculates the total from the adjacent cell through the first nonnumeric cell by default, using the sum function in its formula? -average -autosum -counta -max
Answers: 1
You know the right answer?
Write a program that lets the user play the game of rock, paper, scissors against the computer. the...

Questions in other subjects:

Konu
Mathematics, 23.01.2021 04:30
Konu
Mathematics, 23.01.2021 04:30
Konu
Health, 23.01.2021 04:30
Konu
Mathematics, 23.01.2021 04:30