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 13 of 13

Thread: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR

    Part 1: A Rock Paper Scissors game.

    Rock Paper Scissors is an old game known in many differenct countries. It is a two-player game, and the rules are simple - each player independently makes a choice of Scissors, Paper, or Rock. The two choices are then compared. If both players chose the same value, then the game is a draw; otherwise, Rock loses to Paper (paper can wrap a rock), Paper loses to Scissors (scissors can cut paper), and Scissors loses to Rock (a rock can make scissors blunt).

    You are to write a program that plays Rock-Paper-Scissors with the user. There is a template provided for you that contains two methods. The playRound method should play a single round of Rock-Paper-Scissors with the user and reports the outcome. The playRSPGame method should play a whole game of Rock-Paper-Scissors by calling the playRound method multiple times.

    Core.

    Complete the playRound method so that it makes a random choice for the computer player, then asks the user for their choice, and then reports the computer's choice and whether the user won, lost, or it was a draw.

    For example, if the computer's random choice was scissors and the user chose rock, then the output would be the following (note that it assumes that the user typed "rock" in response to the "Your choice: " question.

    Your choice: rock
    Computer: scissors
    You won.

    If the random choice was paper and the users chose rock, then the output would be:

    Your choice: rock
    Computer: paper
    You lost.

    If both choices were paper then the method should print out:

    Your choice: paper
    Computer: paper
    Draw.

    Complete the playRSPGame method so that it calls the the playRound method 6

    times. You should use a while loop to do this.

    Hints
    To make a random choice, use the Math.random() method to get a random number (double) between 0.0 and 1.0. If the number is less than 0.333, then make one choice; if the number is greater than 0.667, make the second choice, otherwise make the third choice.

    There are quite a lot of cases to handle (9 possible combinations), and therefore your method may be quite long in order to check all of them.

    Completion

    Modify the playRound method so that it also returns an integer which is the score for the user: 1 if the user won, -1 if the user lost, and 0 if it was a draw. Remember that you must specify the type ( int) returned by the method, and you must also have a return statement to return the value.

    Modify the playRSP method so that it will play rounds (by calling playRound), keeping track of the total score of the user, until the user reaches a score of 5 or -5. You will need a variable to keep track of the score, and a while loop that repeatedly calls playRound, adding the result to the score, as long as the score is between -5 and 5.

    Challenge

    Modify the program to keep track of what the user has chosen in the past, and analyse those choices in order to improve the computer's choice. For example, if the user chooses paper more than 1/3 of the time, then the computer will do better to choose scissors. A more sophisticated analysis would look for patterns in the sequence of choices and try to predict the user.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR

    Please read the forum rules. Your other post has been deleted, and this one moved to a more appropriate location. Further, we are not a homework service. If you wish to get help, I recommend reading the link in my signature 'getting help' as well as http://www.catb.org/~esr/faqs/smart-questions.html

  3. #3
    Member
    Join Date
    Mar 2012
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR

    Here is a suggestion
    First make a prototype.
    I would put in this prototype what was said and 3 variables.
    Rock
    Paper
    Scissors.
    I got you started ^-^

  4. #4
    Junior Member
    Join Date
    Apr 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR

    heres what i did so far but i cant get it to give me a draw if hey are the same output!!!!

    public void playRound(){
    String playersChoice = UI.askString("Enter your choice");
    if (playersChoice.equals("rock")){
    UI.println("Your choice: rock");
    }
    else if (playersChoice.equals("paper")){
    UI.println("Your choice: paper");
    }
    else if (playersChoice.equals("scissors")){
    UI.println("Your choice: scissors");
    }
    UI.println("computer:");

    if ( Math.random()<0.333) { // do something with probablity 0.333
    double size = ( double )(Math.random()*1.0); // a random double between 0 and 1.0.
    UI.println("rock");
    }
    if ( Math.random()<0.667) { // do something with probablity 0.667
    double size = ( double )(Math.random()*1.0); // a random double between 0 and 1.0.
    UI.println("paper");
    }
    else {
    UI.println("scissor");
    }
    < if((" Math.random()").equals("playersChoice")){
            UI.println("draw");>
    }
    }
    Last edited by John93; April 8th, 2012 at 08:27 PM.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR

    give me a draw if hey are the same output!!!!
    What lines of the code are not working the way you want?

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Apr 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR

    done bro .

  7. #7
    Junior Member
    Join Date
    Apr 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR

    done .

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR

    Where is a String that holds the value chosen by the computer that you can compare with the value of playersChoice?
    Why is playersChoice in "s? That is probably not what you want to compare against. You want to compare against the contents of playersChoice.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Apr 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR

    well i thought that holds the computers value is math.random which is a double. What do you suggest then to fix it?

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR

    You need to set a String's value according to the value returned by the random() method. You have code that prints out the computer's choice, set the value of a String there.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Apr 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR

    could you tell me how please

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR

    Define a String, assign it a value depending on the value of random, compare it to playersChoice.
    If you don't understand my answer, don't ignore it, ask a question.

  13. The Following User Says Thank You to Norm For This Useful Post:

    John93 (April 8th, 2012)

  14. #13
    Junior Member
    Join Date
    Apr 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR

    could you tell me how please bro

Similar Threads

  1. Rock paper scissors project
    By katie_gsu in forum Loops & Control Statements
    Replies: 1
    Last Post: November 28th, 2011, 02:34 PM
  2. rock paper scissor. whats wrong here ??
    By bjorn10 in forum Loops & Control Statements
    Replies: 1
    Last Post: November 10th, 2011, 09:13 AM
  3. rock paper si
    By robingeldolf in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 4th, 2011, 06:41 AM
  4. MyThesis: rock,paper,scissor..on mobile
    By Cross`17 in forum Java ME (Mobile Edition)
    Replies: 2
    Last Post: April 22nd, 2010, 08:33 AM