subject

// rockpaperscissors. java// plays rock paper scissors with the computer import java. util. scanner; public class rockpaperscissors{ // static class constants static final int rand_limit = 3; static final int num_error = 0; static final int num_rock = 1; static final int num_paper = 2; static final int num_scissors = 3; static final string str_error = "error"; static final string str_rock = "rock"; static final string str_paper = "paper"; static final string str_scissors = "scissors"; static final int player_tie = 0; static final int player_1 = 1; static final int player_2 = 2; public static void main(string[] args) { string inputstr; // general purpose string for input boolean continuing = false; int player1choice = 0, player2choice = 0; int winner = 0; scanner input = new scanner(system. in); // main loop - ask the user if they want to play // and continue if confirmed do { system. out. print("rock, paper scissors: play? (y or n): "); inputstr = input. nextline(); if (! inputstr. equals("y")) continuing = false; else { continuing = true; system. out. println("ok, let's play! "); // player 1 by default is the computer, we may want // want to enhance in the future to allow two humans // (or two computers! ) player1choice = getcomputerchoice(); //system. out. println("player 1 chooses " + player1choice); // debug player2choice = getchoice(input); //system. out. println("player 2 chooses " + player2choice); // debug // echo choice and determine winner system. out. println("computer chose " + choicenumtostring(player1choice) + ", you chose " + choicenumtostring(player2choice)); winner = determinewinner(player1choice, player2choice); // show winner if (winner == player_1) system. out. println("computer wins! "); else if (winner == player_2) system. out. println("you win! "); else system. out. println("tie game! "); } } while(continuing == true); system. out. println("bye! "); } // get, validate, and return the human user's choice public static int getchoice(scanner input) { int choice = num_error; boolean valid = false; while (! valid) { system. out. print(" enter your choice: \n" + "\t1 for rock\n" + "\t2 for paper\n" + "\t3 for scissors" + ": "); choice = input. nextint(); input. nextline(); // clear the buffer valid = isvalid(choice); if (! valid) system. out. println("invalid choice; enter either 1, 2, or 3"); } return choice; }}my rockpaperscissors. java file contains an incomplete implementation of a program which plays the game rock, paper, scissors against the computer. winners are mapped using the following combinations: rock smashes scissorspaper smothers rockscissors cut papera tie occurs if the same object is chosen by both players. the file contains a fully functional main method, various useful constant definitions, and an implementation of the getchoice() method which obtains the game choice from the human user. for this assignment you need to complete the implementation by coding the following methods, for which i have provided the headers, so that the program runs successfully. use the commented method descriptions to guide your implementation. // convert a numeric choice to the corresponding string, // e. g. num_rock returns str_rock public static string choicenumtostring(int choicenum) // get a random value between 1 and 3 (limit) for the computer's choice public static int getcomputerchoice() // return true if ch is valid choice of num_rock, num_paper, or num_scissors public static boolean isvalid(int ch) // get, validate, and return the human user's choice public static int getchoice(scanner input) // determine the winner - returns player_1, player_2, or player_tie public static int determinewinner(int choice1, int choice2)do not modify any constant definition, function header, or the main method (but read the hint provided below). note that i have declared the program constants outside of the main method (above it, actually). doing it this way means that they are available for use outside of the main method, including in the methods you write (this are similar to "global constants").hint: you may want to start out by commenting code in the main method and bring the commented lines back in piece-by-piece as you implement the functions. remember to restore the entire main method back to it's original state when complete so as not to break the above rule about modifying the main method (what i don't see won't hurt output of the game is shown below: rock, paper scissors: play? (y or n): yok, let's play! enter your choice: 1 for rock 2 for paper 3 for scissors: 1computer chose rock, you chose rocktie game! rock, paper scissors: play? (y or n): yok, let's play! enter your choice: 1 for rock 2 for paper 3 for scissors: 1computer chose paper, you chose rockcomputer wins! rock, paper scissors: play? (y or n): yok, let's play! enter your choice: 1 for rock 2 for paper 3 for scissors: 1computer chose scissors, you chose rockyou win! rock, paper scissors: play? (y or n): nbye!

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 03:00
Consider this data sequence: "3 11 5 5 5 2 4 6 6 7 3 -8". any value that is the same as the immediately preceding value is considered a consecutive duplicate. in this example, there are three such consecutive duplicates: the 2nd and 3rd 5s and the second 6. note that the last 3 is not a consecutive duplicate because it was preceded by a 7. write some code that uses a loop to read such a sequence of non-negative integers , terminated by a negative number. when the code finishes executing, the number of consecutive duplicates encountered is printed. in this case, 3 would be printed. assume the availability of a variable, stdin, that references a scanner object associated with standard input. that is, stdin = new scanner(system.in); is given.
Answers: 1
question
Computers and Technology, 23.06.2019 14:30
Select the correct answer. a company wants to use online methods to target more customers. it decides to conduct a market research by collecting the data of a few customers with their consent. they want to track data of the sites that their customers frequently visit. which software can the company? a. spyware b. bots c. adware d. trojan horse e. rootkits
Answers: 1
question
Computers and Technology, 24.06.2019 23:30
True or false when a host gets an ip address from a dhcp server it is said to be configured manually
Answers: 1
question
Computers and Technology, 25.06.2019 00:00
One difference of input method between most desktop computers and most tablets is the memory the touch screen the speech recognition
Answers: 1
You know the right answer?
// rockpaperscissors. java// plays rock paper scissors with the computer import java. util. scanner;...
Questions
question
History, 13.01.2021 20:30
question
Computers and Technology, 13.01.2021 20:30
Questions on the website: 13722360