Java help

Posted on 2013-09-20
Medium Priority
Last Modified: 2013-09-20
I need help finishing up my program, the problem is this, Remember the childhood game “Rock, Paper, Scissors”? It is a two-player 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. The following code prompts player 1 and player 2 to each enter a string: rock, paper, or scissors. Finish the code by adding nested if statements to appropriately report “Player 1 wins”, “Player 2 wins”, or “It is a tie.”

I already have this :

import java.util.Scanner;
public class RockPaperScissors {
public static void main(String[] args)     {
    Scanner scan = new Scanner(System.in);
    System.out.println("Player 1: Choose rock, scissors, or paper:");  
    String player1 = scan.next().toLowerCase();
    System.out.println("Player 2: Choose rock, scissors, or paper:");

Can you help me?
Question by:TheChos
  • 2
  • 2
LVL 37

Expert Comment

ID: 39509025
What you already have is what the assignment gave you. You haven't done anything yet.
We cannot do your homework for you, but we can help; however, in order to do that, we need to know what is blocking you. What is it that you do not know how to do?
So you are supposed to be writing "nested ifs." Can you write the logic using pseudo code? (i.e. English but in a code looking way something like
if player1 chose rock
   if player2 chose paper

Author Comment

ID: 39509102
thats what I need help with I do not quite understand how to do if player1 chose rock part and how its set up
LVL 37

Accepted Solution

TommySzalapski earned 2000 total points
ID: 39509146
Write it in English
Remember everything inside the if block (between the { and } ) only happens if the if condition was true.

if (player 1 chose rock)
   if (player2 chose paper)
        what happens here?
   else if ( what other conditions need to be checked?)
else if (player 1 chose scissors)
   if (player 2 ....)

Author Comment

ID: 39509543
Thank you this helped me alot

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This algorithm (in C#) will resize any image down to a given size while maintaining the original aspect ratio. The maximum width and max height are both optional but if neither are given, the original image is returned. This example is designed t…
When there is a disconnect between the intentions of their creator and the recipient, when algorithms go awry, they can have disastrous consequences.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question