Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Beginner Help

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Beginner Help

    Hey guys this is my first post. I am fairly new to Java and it would be much appreciated if I could get some help.

    I am trying to solve this homework problem.
    Game: scissor, rock, paper) Write a program that plays the popular scissor-rock- paper game. (A scissor can cut a paper, a rock can knock a scissor, and a paper can wrap a rock.) The program randomly generates a number 0, 1, or 2 representing scissor, rock, and paper. The program prompts the user to enter a number 0, 1, or 2 and displays a message indicating whether the user or the computer wins, loses, or draws.

    This is what I currently have and I am stuck here. Anything would be helpful!

    //Create a Scanner for Input
        Scanner input = new Scanner(System.in);
     
        //Pick a scissor (0), rock (1), paper (2)
        System.out.print ("scissor (0), rock (1), paper (2):  ");
     
        //Pick aRandomNumber between 0 and 2
        int aRandomNumber = (int) (Math.random() * 3);
     
        //Determine if scissor (0), rock (1), paper (2)
        int result = aRandomNumber;
        String hand;
        if (result == 0) {
            hand = " scissor";
        }
        else if (result == 1) {
            hand = " rock";
        }
        else if (result == 2) {
            hand = " paper";
        }
     
     
        System.out.println("Enter scissor (0), rock (1), paper (2)"
                + aRandomNumber +);
     
        //
     
     
     
        }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,592
    Thanks
    50
    Thanked 2,235 Times in 2,207 Posts

    Default Re: Beginner Help

    Can you explain what problems you are having? What are you stuck on?

    Have you worked out the steps the program must do to play this game? You need to have done that before trying to write any code.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Beginner Help

    I am having a problem with the command asking me to pick a number (0-2). It always fails. Sorry if this is a bad explanation, I am new to Java.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,592
    Thanks
    50
    Thanked 2,235 Times in 2,207 Posts

    Default Re: Beginner Help

    problem with the command asking me to pick a number (0-2). It always fails.
    Please explain what "fails" means. If there is an error message, copy it and paste it here.

    On windows: To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Feb 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Beginner Help

    This is in my command window as of right now.

     //Create a Scanner for Input
        Scanner input = new Scanner(System.in);
     
        //Pick aRandomNumber between 0 and 2
        int computerNumber = (int) (Math.random() * 3);
     
        //Pick a scissor (0), rock (1), paper (2)
        System.out.print ("scissor (0), rock (1), paper (2):  ");   
     
        //Determine if scissor (0), rock (1), paper (2)
        int result = computerNumber;
        String hand;
        if (result == 0) {
            hand = " scissor";
        }
        else if (result == 1) {
            hand = " rock";
        }
        else if (result == 2) {
            hand = " paper";
        }
     
     
        System.out.println(" The computer is " + hand + "You are " 
     
     
     
        }
    }


    I get this message:

    run:
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>
    scissor (0), rock (1), paper (2): at rockscissorspaper.java.RockScissorsPaperJava.main( RockScissorsPaperJava.java:43)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 1 second)

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,592
    Thanks
    50
    Thanked 2,235 Times in 2,207 Posts

    Default Re: Beginner Help

    What line is line 43? The IDE doesn't give good compiler error messages. If you'd use the javac command to compile the code the error messages would be much better.
    Here is a sample:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. beginner
    By reginakanje in forum Object Oriented Programming
    Replies: 2
    Last Post: January 12th, 2013, 05:09 AM
  2. Beginner help please.
    By xdorkiee in forum What's Wrong With My Code?
    Replies: 59
    Last Post: December 20th, 2012, 08:19 PM
  3. Beginner
    By mkarthik90 in forum Member Introductions
    Replies: 1
    Last Post: February 18th, 2012, 01:26 PM
  4. Beginner
    By codejava in forum Member Introductions
    Replies: 2
    Last Post: August 22nd, 2011, 08:11 AM
  5. Beginner
    By angelo24 in forum Member Introductions
    Replies: 1
    Last Post: August 19th, 2011, 07:14 AM