Question

In: Computer Science

Create a rock paper scissors game against the computer using bunch of methods. -No two dimensional...

Create a rock paper scissors game against the computer using bunch of methods.

-No two dimensional arrays

-No java.util.random

-No ragged arrays

-Methods only, and one dimensional arrays

Solutions

Expert Solution


import java.util.*;
import java.lang.Math;

class RPS_Game
{
public static int result(String player1, String player2){
if(player1.equalsIgnoreCase("rock") && player2.equalsIgnoreCase("rock"))
return 0;
else if(player1.equalsIgnoreCase("rock") && player2.equalsIgnoreCase("scissors"))
return 1;
else if(player1.equalsIgnoreCase("rock") && player2.equalsIgnoreCase("paper"))
return 2;
else if(player1.equalsIgnoreCase("scissors") && player2.equalsIgnoreCase("rock"))
return 2;
else if(player1.equalsIgnoreCase("scissors") && player2.equalsIgnoreCase("scissors"))
return 0;
else if(player1.equalsIgnoreCase("scissors") && player2.equalsIgnoreCase("paper"))
return 1;
else if(player1.equalsIgnoreCase("paper") && player2.equalsIgnoreCase("rock"))
return 1;
else if(player1.equalsIgnoreCase("paper") && player2.equalsIgnoreCase("scissors"))
return 2;
else if(player1.equalsIgnoreCase("paper") && player2.equalsIgnoreCase("paper"))
return 0;
return -1;
}
public static void main(String[] args) {
String player1,player2;
int compVal;
Scanner sc=new Scanner(System.in);
System.out.println("Player : Choose rock, scissors, or paper:");
player1=sc.nextLine();
System.out.println("Computer : Choose rock, scissors, or paper:");
compVal=(int)((Math.random()*10)%3);
if(compVal==0)
player2 ="rock";
else if (compVal==1)
player2 ="scissor";
else
player2 = "paper";
if(result(player1,player2)==1){
System.out.println("Player wins");
} else if(result(player1,player2)==2){
System.out.println("Computer wins");
} else if(result(player1,player2)==0){
System.out.println("It is a tie");
} else {
System.out.println("Wrong choice!");
}
}
}


Related Solutions

JAVA : Design and implement an application that plays the Rock-Paper-Scissors game against the computer. When...
JAVA : Design and implement an application that plays the Rock-Paper-Scissors game against the computer. When played between two people, each person picks one of three options (usually shown by a hand gesture) at the same time, and a winner is determined. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should randomly choose one of the three options (without revealing it) and then prompt for the user’s selection. At that point, the program...
Design and implement an Android application that plays the Rock-Paper-Scissors game against the computer. When played...
Design and implement an Android application that plays the Rock-Paper-Scissors game against the computer. When played between two people, each person picks one of three options (usually shown by a hand gesture) at the same time, and a winner is determined. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should randomly choose one of the three options (without revealing it) and then seek for the user’s selection (using your choice of an object...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the computer through a user interface. The user will choose to throw Rock, Paper or Scissors and the computer will randomly select between the two. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should then reveal the computer's choice and print a statement indicating if the user won, the computer won, or if it was a tie. Allow...
Problem Description: You have to play the rock-paper-scissors game against the computer for 100 times. You...
Problem Description: You have to play the rock-paper-scissors game against the computer for 100 times. You receive the following rewards each time you play the game:  You get $5 if you win  You get $2 if there is a tie  You get $-1 if you lose The computer randomly chooses rock, paper, or scissors in each game. Rather than deciding what to play (rock, paper or scissors) for each individual game, you decide to use the following...
Rock-Paper-Scissors Implement Rock-Paper-Scissors such that the user can play the computer in a best-of series! The...
Rock-Paper-Scissors Implement Rock-Paper-Scissors such that the user can play the computer in a best-of series! The user inputs the number of rounds which should be positive and odd. This is a free form assignment but structure your code similar to the test cases provided. USING MATLAB ONLY!!! Program Inputs • How many rounds would you like to play (odd rounds only)?: XXX – XXX should be positive and odd. Restart the game if the input is not positive or odd....
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper,...
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper, or scissors. If both players choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows: • Rock beats scissors, because a rock can break a pair of scissors. • Scissors beats paper, because scissors can cut paper. • Paper beats rock, because a piece of paper can cover a rock. Create a game...
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper,...
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper, or scissors. If both players choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows: • Rock beats scissors, because a rock can break a pair of scissors. • Scissors beats paper, because scissors can cut paper. • Paper beats rock, because a piece of paper can cover a rock. Create a game...
Code the game of Rock, Paper, Scissors between a human player and the computer. You can...
Code the game of Rock, Paper, Scissors between a human player and the computer. You can check out the game on Wikipedia if you are not familiar with it. Create a 4 option menu with the human player choices, plus the option of exiting the game. Randomly determine the computer’s choice (although a great deal of AI research has gone in to determining the best computer move). • Loop the game until the human player exits. • Count the number...
1.Create full program in Java that will simulate a Rock Paper Scissors Game You will create...
1.Create full program in Java that will simulate a Rock Paper Scissors Game You will create the code so that when the program is run the user will see in the console the following: We are going to play rock paper scissors. Please choose 1 for Rock 2 for Paper or 3 for scissors. The program will have your choice which is the integer-valued typed in by the user and compChoice which will be the randomly generated value of either...
write a python script for rock scissors paper game
write a python script for rock scissors paper game
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT