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, 23.06.2019 19:00
Write a program that displays the following menu: geometry calculator 1. calculate the area of a circle 2. calculate the area of a rectangle 3. calculate the area of a triangle 4. quit enter your choice (1-4): if the user enters 1, the program should ask for the radius of the circle and then display its area. use the following formula: area = ď€(the square of r) use 3.14159 for ď€ and the radius of the circle for r. if the user enters 2, the program should ask for the length and width of the rectangle and then display the rectangle’s area. use the following formula: area = length * width if the user enters 3, the program should ask for the length of the triangle’s base and its height, and then display its area. use the following formula: area = base * height * .5 if the user enters 4, the program should end. input validation: display an error message if the user enters a number outside the range of 1 through 4 when selecting an item from the menu. do not accept negative values for the circle’s radius, the rectangle’s length or width, or the triangle’s base or height. note: if the user enters an improper menu choice (1-4), the program prints "the valid choices are 1 through 4. run the program again and select one of those." if the user enters a negative radius, the program prints "the radius can not be less than zero." if the user enters a negative value for height or base, the program prints "only enter positive values for base and height."
Answers: 1
question
Computers and Technology, 23.06.2019 22:30
What would be the address of the cell, which is at the intersection of the second row and the third column in a worksheet?
Answers: 1
question
Computers and Technology, 24.06.2019 00:30
Which boolean operator enables you to exclude a search term? a} not b} and c} or d} plus
Answers: 1
question
Computers and Technology, 24.06.2019 02:00
Read the following scenario, and then answer the question below. you want to send an e-mail to your boss requesting a meeting to discuss a raise. what is the best example of an e-mail to an employer about this meeting? “hey jason. can we chat about getting me more money soon? let me know. peace, meg.” “hello jason. pardon me for sending yet another e-mail today about my need to talk to you about my position and a possible pay increase. i am dying to know when you can talk. sincerely, meg.” “hello jason. i have been with the company for one year and have taken on more responsibilities than outlined in my job description. i would appreciate an opportunity to speak with you about my position. let me know when we can schedule a meeting. you, meg.” “greetings jason! i hope this e-mail finds you well and happy today. i really, really want to talk to you about something important. i am not sure if you have time. i hope you do. get back in touch with me and let me know when we might talk. ever so much for taking the time to read this. sincerely, meg.”
Answers: 3
You know the right answer?
// rockpaperscissors. java// plays rock paper scissors with the computer import java. util. scanner;...
Questions
question
Mathematics, 25.11.2020 01:40
question
Business, 25.11.2020 01:40
question
Mathematics, 25.11.2020 01:40
Questions on the website: 13722363