Question

In: Computer Science

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 such as editText, button etc., ). At that point, the program reveals both choices and shows a message (as a Toast or another Text field) indicating whether the user won, the computer won, or it was a tie.

Notes:

  1. The code of your app is to be written in Kotlin.
  2. Points will be deducted for missing comments, extraneous semicolons and for extraneous parentheses in flow control statements (loop and decision statements).

Submission:

  • After closing your project in Android Studio, compress (zip) the project folder and submit the zip file.

PreviousNext

Solutions

Expert Solution

Solution:

import java.util.Random;
import java.util.Scanner;

public class RockScissorPaperGame {

public static final String ROCK = "ROCK";
public static final String PAPER = "PAPER";
public static final String SCISSORS = "SCISSORS";

public static void main(String args[]) {
int totalGames = 0, wins = 0, losses = 0,ties=0;
do {
totalGames++;
System.out.println("Enter any one of the following inputs: ");
System.out.println("ROCK");
System.out.println("PAPER");
System.out.println("SCISSORS");
System.out.println();
String playerMove = getPlayerMove().toUpperCase();
String computerMove = getComputerMove();

if (playerMove.equals(computerMove)) {
System.out.println("Its tie !!");
ties++;
} // if player selects ROCK
else if (playerMove.equals(ROCK)) {
if (computerMove.equals(PAPER)) {
System.out.println("Computer wins");
losses++;
} else {

System.out.println("Player wins");
wins++;
}
} // if player selects PAPER
else if (playerMove.equals(PAPER)) {
if (computerMove.equals(SCISSORS)) {
System.out.println("Computer wins");
losses++;
} else {
System.out.println("Player wins");
wins++;
}
} // if player selects SCISSORS
else {
if (computerMove.equals(ROCK)) {
System.out.println("Computer wins");
losses++;
} else {
System.out.println("Player wins");
wins++;
}
}
} while (playAgain());
System.out.println("Total Games: "+totalGames);
System.out.println("Wons: "+wins);
System.out.println("Losses: "+losses);
System.out.println("Ties: "+ties);
}

public static String getComputerMove() {
String computermove;
Random random = new Random();
int input = random.nextInt(3) + 1;
if (input == 1) {
computermove = ROCK;
} else if (input == 2) {
computermove = PAPER;
} else {
computermove = SCISSORS;
}

System.out.println("Computer Pick is: " + computermove);
System.out.println();
return computermove;
}

public static String getPlayerMove() {
Scanner in = new Scanner(System.in);
String input = in.next();
String playermove = input.toUpperCase();
System.out.println("Player move is: " + playermove);
return playermove;
}

public static boolean playAgain() {
Scanner sc = new Scanner(System.in);
System.out.print("Do you want to play again? ");
String userInput = sc.nextLine();
userInput = userInput.toUpperCase();
return userInput.charAt(0) == 'Y';
}
}

**********************************Thank You******************************


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...
Many of you probably played the game “Rock, Paper, Scissors” as a child. Consider the following...
Many of you probably played the game “Rock, Paper, Scissors” as a child. Consider the following variation of that game. Instead of two players, suppose three players play this game, and let us call these players A, B, and C. Each player selects one of these three items—Rock, Paper, or Scissors—independent of each other. Player A will win the game if all three players select the same item, for example, rock. Player B will win the game if exactly two...
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...
Game Description: The popular rock-paper-scissors game is usually played between two people in which each player...
Game Description: The popular rock-paper-scissors game is usually played between two people in which each player simultaneously chooses either a rock or a paper or scissors (usually with an outstretched hand). The rule of the game is simple: rock crushes scissors, scissors cut paper, and paper wraps rock. If both the players choose the same object, then it ends in a tie. Problem Description: You have to play the rock-paper-scissors game against the computer for 100 times. You receive the...
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. Have you ever played rock-paper-scissors (or Rochambeau)? It’s considered a “fair game” in that the...
1. Have you ever played rock-paper-scissors (or Rochambeau)? It’s considered a “fair game” in that the two players are equally likely to win (like a coin toss). Both players simultaneously display one of three hand gestures (rock, paper, or scissors), and the objective is to display a gesture that defeats that of your opponent. The main gist is that rocks break scissors, scissors cut paper, and paper covers rock. We investigated some results of the game rock-paper-scissors, where the researchers...
Solve the scissors, paper, rock game. This game is well known in many parts of the...
Solve the scissors, paper, rock game. This game is well known in many parts of the world. Two players simultaneously present a hand in one of three positions: an open hand (paper), a closed fist (rock), or two open fingers (scissors). The payoff is 1 unit according to the rule “Paper covers rock, rock breaks scissors, and scissors cut paper.” If both players present the same form, the payoff is 0. Set up the payoff matrix for the game and...
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...
Suppose you play rock paper scissors against a computer: *you gain $1 for each win *you...
Suppose you play rock paper scissors against a computer: *you gain $1 for each win *you lose $1 for each lost if it is a tie, nothing happens you choose rock 50% of the time and the others 25% of the time let x be a random variable that represents the amount of money you earn after one game. (a) find the probability distribution of X (b) what is your average payoff after 20 games? (c) what is the standard...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT