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, 21.06.2019 22:30
Provide an example of a project that combines the three principles of lean six sigma with business project management (bpm) and services oriented architecture (soa). identify the elements of the project that comply with each of three principles.
Answers: 1
question
Computers and Technology, 22.06.2019 20:10
Assume that minutes is an int variable whose value is 0 or positive. write an expression whose value is "undercooked" or "soft-boiled" or "medium-boiled" or "hard-boiled" or "overcooked" based on the value of minutes. in particular: if the value of minutes is less than 2 the expression's value is "undercooked"; 2-4 would be a "soft-boiled", 5-7 would be "medium-boiled", 8-11 would be "hard-boiled" and 12 or more would be a "overcooked".
Answers: 1
question
Computers and Technology, 23.06.2019 14:30
The option enables you to modify a slide element in most presentation applications.
Answers: 2
question
Computers and Technology, 23.06.2019 15:30
Brian wants to conduct an online search with a certain phrase. he intends to use the words books that belong to the 1800s in his search. how should he use the word that in his search?
Answers: 1
You know the right answer?
// rockpaperscissors. java// plays rock paper scissors with the computer import java. util. scanner;...
Questions
question
Mathematics, 24.07.2020 08:01
question
Mathematics, 24.07.2020 08:01
Questions on the website: 13722362