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

Java) Write a program to score the rock-paper-scissor game. Each of two users types in either...
Java) Write a program to score the rock-paper-scissor game. Each of two users types in either R, P, S or Q to quit. The program then announces the winner as well as the basis for determining the winner: Paper covers rock, Rock breaks scissors, Scissors cut paper, or a Tie game. Allow the user to use lowercase as well as uppercase letters. Your program should loop until the user types a 'Q' to quit. In the sample code, the game...
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...
Subjects: Write a Python program that allows users to play the popular rock-paper-scissor game against the...
Subjects: Write a Python program that allows users to play the popular rock-paper-scissor game against the computer multiple times. This program assesses your knowledge of decision structures, repetition structures, and functions. Requirements: 1.Define a function named as play_game. This function receives two parameters representing the player’s and computer’s choices, and it returns an integer representing the game result from the player’s perspective. Specifically, it returns 1 if the player wins and 0 if the player does not win. Hint: you...
Write a C++ program to score the paper-rock-scissor game. Each of two players (player1 and player2)...
Write a C++ program to score the paper-rock-scissor game. Each of two players (player1 and player2) input a character which could be either ‘P’, ‘R’, or ‘S’ (in uppercase or lowercase). For any other input character should display a message “Invalid input”. The program then announces who is the winner as well as the basis for determining the winner which could be one of the following: “Paper covers rock”, “Rock breaks scissors”, “Scissors cut paper”, or “Nobody wins”. (Use switch...
Write a C++ program to score the paper-rock-scissor game. Each of two players (player1 and player2)...
Write a C++ program to score the paper-rock-scissor game. Each of two players (player1 and player2) input a character which could be either ‘P’, ‘R’, or ‘S’ (in uppercase or lowercase). For any other input character should display a message “Invalid input”. The program then announces who is the winner as well as the basis for determining the winner which could be one of the following: “Paper covers rock”, “Rock breaks scissors”, “Scissors cut paper”, or “Nobody wins”. (Use switch...
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...
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...
Create a Java program that allows two players to play Rock, Paper, Scissors. Player 1 will...
Create a Java program that allows two players to play Rock, Paper, Scissors. Player 1 will enter an integer to determine whether they use rock, paper or scissors. Player 2 will also enter an integer to determine whether they use rock, paper or scissors. Use named constants for rock, paper and scissors and set their values as shown below. Use if-else statements to determine the results of the game. Use the named constants to compare with the player 1 and...
Application on Android Studio.   "Rock Paper Scissor". The app should ask the user to select "Rock",...
Application on Android Studio.   "Rock Paper Scissor". The app should ask the user to select "Rock", "Paper" or "Scissor" ; the phone randomly selects a possible choice and then a winner is declared; if it is a tie, the game should continue till a winner emerges.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT