Question

In: Computer Science

JAVA PROGRAM, Create the game "Rock, Scissor, Paper": Make the AI pick randomly. You need to...

JAVA PROGRAM, Create the game "Rock, Scissor, Paper":

  1. Make the AI pick randomly. You need to look up Random numbers in Java.
  2. First ask the user what language they want to play in. Choice 1 is English, but choice 2 can be whatever real language you want.
  3. Your first loop is making sure they enter good input.
  4. If there is a tie you don't give them the option to play again. They have to.
  5. Outer loop runs until they say they don't want to play again.
  6. Display how many wins and losses the player had only after they quit. Remember, variables are free. If you need the computer to keep track of something, make a variable.

Solutions

Expert Solution

Dear student,

The below code is for english language. for any other language add if statement for each print statement based language variable.

import java.util.Scanner;
import java.util.Random;
public class Main
{
   public static void main(String[] args) {
   int language=1;
   int choice=0;
   int computerChoice=0;
   int winOrLose=0;
   int PlayerWins=0;
   int ComputerWins=0;
   int continueGame=0;
  
       System.out.println("Welcome");
       System.out.println("Press 1 for english \nPress 2 for French");
       Scanner myObj = new Scanner(System.in);
       Random rand = new Random();
       language = myObj.nextInt();
       while(language != 1&&language!=2)
       {
       System.out.println("Press 1 for english \nPress 2 for French");
       language = myObj.nextInt();
       }
       while(true)
       {
       System.out.println("Please choose Rock Paper Scissor");
       System.out.println("Press 1 for Rock");
       System.out.println("Press 2 for Paper");
       System.out.println("Press 3 for Scissor");
       choice = myObj.nextInt();
       while(choice != 1&&choice!=2&&choice!=3)
       {
       System.out.println("Press 1 for Rock");
       System.out.println("Press 2 for Paper");
       System.out.println("Press 3 for Scissor");
       choice = myObj.nextInt();
       }
      
computerChoice = rand.nextInt(3) + 1;
System.out.println("Computer chose "+computerChoice);
      
       if(choice==computerChoice)
       {
       System.out.println("Draw");
       winOrLose=0;
       }
       else if((choice==1&&computerChoice==2)||(choice==2&&computerChoice==3)||(computerChoice==1&&choice==3))
       {
       System.out.println("Computer Wins");
       winOrLose=2;
       }
       else if((computerChoice==1&&choice==2)||(computerChoice==2&&choice==3)||(choice==1&&computerChoice==3))
       {
       System.out.println("Player Wins");
       winOrLose=1;
       }
      
       if(winOrLose==1)
       PlayerWins++;
       else if(winOrLose==2)
       ComputerWins++;
      
       if(winOrLose!=0)
       {
       System.out.println("\n\npress 1 to continue press 2 to exit");
       continueGame = myObj.nextInt();
       }
       if(continueGame==2)
       {
       break;
       }
       }
       System.out.println("Player Total wins = "+PlayerWins);
       System.out.println("Computer Total wins = "+ComputerWins);
   }
}

Screenshot of output

If you have any doubt please comment below also dont forget to hit the like button thank you :)


Related Solutions

Write a Java program that plays the game Rock, Paper, Scissors. The program should generate a...
Write a Java program that plays the game Rock, Paper, Scissors. The program should generate a random choice (Rock, Paper or Scissors) then ask the user to choose Rock, Paper or Scissors. After that the program will display its choice and a message showing if the player won, lost or tied. Next, the program should prompt the user to play again or not. Once the player selects to stop playing the game, the program should print the number of wins,...
One file java program that will simulate a game of Rock, Paper, Scissors. One of the...
One file java program that will simulate a game of Rock, Paper, Scissors. One of the two players will be the computer. The program will start by asking how many winning rounds are needed to win the game. Each round will consist of you asking the user to pick between rock, paper, and scissors. Internally you will get the computers choice by using a random number generator. Rock beats Scissors, Paper beats Rock, and Scissors beats Paper. You will report...
JAVA Remember the childhood game “Rock, Paper, Scissors”? It is a two-players game in which each...
JAVA Remember the childhood game “Rock, Paper, Scissors”? It is a two-players game in which each person simultaneously chooses either rock, paper, or scissors. Rock beats scissors but loses to paper, paper beats rock but loses to scissors, and scissors beats paper but loses to rock. Your program must prompt the player 1 and player 2 to each enter a string for their choice: rock, paper, or scissors. Then appropriately reports if “Player 1 wins”, “Player 2 wins”, or “It...
Write a Java class that determines the winner of a rock, paper scissors game. Assume the...
Write a Java class that determines the winner of a rock, paper scissors game. Assume the input from the user is always valid (so no need to check), that is it contains either one of `R`, `P`, or `S` as a single character, or has matching parenthesis, like, `(S&P)` or `((R&P)&S)`, and the `&` character. So for example, the user inputs `(P&R)` and the program will output `P` since paper beats rock. Or if the user inputs `((S&R)&(S&S))` the output...
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game...
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: You can set these constant global variables at the top outside of your main function definition: COMPUTER_WINS = 1 PLAYER_WINS = 2 TIE = 0 INVALID = 3 ROCK = 1 PAPER = 2 SCISSORS = 3 For this program 1 represents rock, 2 represents paper, and 3 represents scissors. In...
Need to make Java code as following: Create a dice playing threading program to do the...
Need to make Java code as following: Create a dice playing threading program to do the following: 1. Start a thread for a process to simulate a computer rolling a die 1000 times. 2. Start another thread for a process to simulate a user rolling a die 1000 times. 3. Keep track of rolls for user and computer in an array(s). 4. Display on screen when the computer thread starts, the rolls, and when the computer thread ends. 5. Display...
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...
in java we need to order a list , if we create a program in java...
in java we need to order a list , if we create a program in java what  are the possible ways of telling your program how to move the numbers in the list to make it sorted, where each way provides the required result. list the name of sorting with short explanation
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT