Question

Your non-programmer friends have challenged your Java programming skills, and you are going to prove them...

Your non-programmer friends have challenged your Java programming skills, and you are going to prove them wrong. Write a program that will play rock, paper, scissors against them, but since we are annoyed at this challenge, write it in such a way that it can never lose. However, it must be able to tie so that they dont get TOO suspicious. In your main, ask the user to enter their choice - rock, paper or scissors. Write a method that given the user's choice, generates and returns the computer's choice. It should randomly pick the winning choice or tie the user's choice. As your output, show both the user's and the computer's choice and declare the winner or the tie. Keep asking the user if they want to play until they give up and you have claimed your superiority.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Random;
import java.util.Scanner;
public class rockPaperScissors {
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       // 1 - Rock 2 - Paper 3 - Scissors
       // Anything will be beaten by its next one and will beat the previous one
       Random rand = new Random();
       Scanner scan = new Scanner(System.in);
       int in,out,sout;
       String con;
       while(true)
       {
           int rn = rand.nextInt(2) - 1;
           //System.out.println(randomNum);
           System.out.println("Please select one of the following:");
           System.out.println("1. Rock");
           System.out.println("2. Paper");
           System.out.println("3. Scissors");
           System.out.print("Which one would you like to choose?");
           in = scan.nextInt();
           rn = rand.nextInt(2);
           out = (in+rn);
           sout=out;
           if(sout>3)
           {
               sout = sout-3;
           }
           System.out.println("Computer's choice: "+sout);
           if(in==out)
           {
               System.out.println("The Game is a tie.");
           }
           else if(out-in==1)
           {
               System.out.println("Computer won the Game.");
           }
           System.out.print("Would you like to continue? (Y/N)");
           con = scan.next();
           if(con.equals("N"))
           {
               break;
           }
       }
   }
}

Add a comment
Know the answer?
Add Answer to:
Your non-programmer friends have challenged your Java programming skills, and you are going to prove them...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • It's writing a simple rock paper scissors game strictly following the instructions. INSTRUCTIONS: If the user...

    It's writing a simple rock paper scissors game strictly following the instructions. INSTRUCTIONS: If the user selects 'p': 1. First the program should call a function named getComputerChoice to get the computer's choice in the game. The getComputerChoice function should generate a random number between 1 and 3. If the random number is 1 the computer has chosen Rock, if the random number is 2 the user has chosen Paper, and if the random number is 3 the computer has...

  • You are asked to implement scissors-rock-paper game where the players are a computer and a user....

    You are asked to implement scissors-rock-paper game where the players are a computer and a user. The player that wins 3 hands successively is the winner of the game. Your program should prompt the user with a message at the beginning of each hand to enter one of scissors, rock or paper. If the user's entry is not valid, i.e. entry is neither scissors, rock, nor paper, your program throws a message to the user to enter a valid entry...

  • java pls Rock Paper Scissors Lizard Spock Rock Paper Scissors Lizard Spock is a variation of...

    java pls Rock Paper Scissors Lizard Spock Rock Paper Scissors Lizard Spock is a variation of the common game Rock Paper Scissors that is often used to pass time (or sometimes to make decisions.) The rules of the game are outlined below: • • Scissors cuts Paper Paper covers Rock Rock crushes Lizard Lizard poisons Spock Spock smashes Scissors Scissors decapitates Lizard Lizard eats Paper Paper disproves Spock Spock vaporizes Rock Rock crushes Scissors Write a program that simulates the...

  • In python language Write a program that lets the user play the game of Rock, Paper,...

    In python language Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: 1. When the program begins, a random number in the range of 1 and 3 is generated. 1 = Computer has chosen Rock 2 = Computer has chosen Paper 3 = Computer has chosen Scissors (Dont display the computer's choice yet) 2. The user enters his or her choice of “Rock”, “Paper", “Scissors" at...

  • JAVA Beginnings of a paper-rock-scissors game. Paper-rock-scissors is a game often used to make decisions. There...

    JAVA Beginnings of a paper-rock-scissors game. Paper-rock-scissors is a game often used to make decisions. There are two players. Each player secretly chooses either, paper, rock or scissors. At the count of three, each player reveals what they have chosen. The winner of the game is determined this way: paper beats rock (because paper covers rock) rock beats scissors (because rock crushes scissors) scissors beat paper (because scissors cut paper) If the two players choose the same item, it is...

  • Write a program in the Codio programming environment that allows you to play the game of...

    Write a program in the Codio programming environment that allows you to play the game of Rock / Paper / Scissors against the computer. Within the Codio starting project you will find starter code as well as tests to run at each stage. There are three stages to the program, as illustrated below. You must pass the tests at each stage before continuing in to the next stage.  We may rerun all tests within Codio before grading your program. Please see...

  • Please help I am struggling with this and 3*Math.random())+1; and how to use it within the...

    Please help I am struggling with this and 3*Math.random())+1; and how to use it within the program For this project you will write a Java program that will play a simple game of Rock, Paper, Scissors.  If you have never played this game before the rules are simple - each player chooses one of Rock, Paper or Scissors and they reveal their choices simultaneously. • The choice of Rock beats the choice of Scissors ("Rock smashes Scissors") • The choice of...

  • In java language here is my code so far! i only need help with the extra...

    In java language here is my code so far! i only need help with the extra credit part For this project, you will create a Rock, Paper, Scissors game. Write a GUI program that allows a user to play Rock, Paper, Scissors against the computer. If you’re not familiar with Rock, Paper, Scissors, check out the Wikipedia page: http://en.wikipedia.org/wiki/Rock-paper-scissors This is how the program works: The user clicks a button to make their move (rock, paper, or scissors). The program...

  • I have to use java programs using netbeans. this course is introduction to java programming so...

    I have to use java programs using netbeans. this course is introduction to java programming so i have to write it in a simple way using till chapter 6 (arrays) you can use (loops , methods , arrays) You will implement a menu-based system for Hangman Game. Hangman is a popular game that allows one player to choose a word and another player to guess it one letter at a time. Implement your system to perform the following tasks: Design...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT