Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Unhappy Rock, paper scissor game

    I have most of my code done but i can't figure out how to put in the follwing:

    Please enter the number of rounds you would like to play: 2
    Sorry, you need to enter an odd number. Please try again: 3
    Rock, Paper, or Scissors?: Monkey
    Sorry, “Monkey” is not a valid entry.

    I know the rest need help with this?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    what do you want me to enter my whole code in there i told you i have the rest done i just need help with this section because im not sure how to do this part!! IM not asking you to do the whole assignment for me!!!!!!!:mad:

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by katnisseverdeen View Post
    what do you want me to enter my whole code in there i told you i have the rest done i just need help with this section because im not sure how to do this part!! IM not asking you to do the whole assignment for me!!!!!!!:mad:
    Please show me where in my post I accused you of this. I do feel strongly though that we need to see your attempt else we have no idea what you do or don't understand. Also, you need to ask more specific questions -- just what confuses you. All we've seen is your code requirement but we have no inkling as to what's hanging you up. Also, the more you attempt, whether it succeeds or nor, the more you will learn.

    Luck.

  5. #5
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    Java Code:
    
    
    import java.util.Scanner;
    import java.util.Random
     
    
    public class RockPaperScissor{
    
        public static void main(String [] args){
    
             
            int computerRandom;
    
            String userInput = "";
    
            char userChoice = 'j' ;
    
            char computerChoice = 'j';
    
            int computerWin = 0;
    
            int userWin = 0;
    
             
    
            Random random = new Random();
    
            Scanner reader = new Scanner (System.in);
    
             
                
                while(userChoice != 'rock' && userChoice != 'paper' && userChoice != 'scissors'){
    
                        System.out.print("\nPlease input Rock, Paper or Scissor: ");
    
                        
    
                   		userInput = reader.nextLine();
    
                        userChoice = userInput.charAt(0);
    
                        System.out.print("\n" +userChoice);
    
                }
             
    
                computerRandom = random.nextInt(3);
    
                switch (computerRandom){
    
                    case 1: computerChoice = 'rock'; break;
                    case 2: computerChoice = 'paper'; break;
                    case 3: computerChoice = 'scissors'; break;
    
                }
    
                 
                if (computerChoice == userChoice){
    
                    System.out.print("\nTie ");
    
                }else{
    
                    if (computerChoice  == 'rock'){
    
                        if (userChoice == 'paper'){
    
                            System.out.print("\nPaper beats rock, you win!");
    
                            userWin++;
    
                        }
    
                        if (userChoice == 's'){
    
                            System.out.print("\nRock beats scissor, you lose!");
    
                            computerWin++;
    
                        }
    
                    }
    
                    if (computerChoice  == 'paper'){
    
                        if (userChoice == 'rock'){
    
                            System.out.print("\nPaper beats rock, you lose!");
    
                            computerWin++;
    
                        }
    
                        if (userChoice == 'scissors'){
    
                            System.out.print("\nScissors beat paper, you win!");
    
                            userWin++;
    
                        }
    
                    }
    
                    if (computerChoice  == 'scissors'){
    
                        if (userChoice == 'rock'){
    
                            System.out.print("\nRock beats Scissor, you lose!");
    
                            computerWin++;
    
                        }
    
                        if (userChoice == 'paper'){
    
                          System.out.print("\nPaper beats rock, you win!");
    
                            userWin++;
    
                        }
    
                    }
    
                }
    
              System.out.print("\nThe score is: user: " + userWin + " computer: " + computerWin);
    
            }
    
        }

  6. #6
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    did that work?

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    There are lots of problems in the code above, but the major one is that a char can only be that, a single char.

    So this won't work:

    Java Code:
    if (userChoice != 'rock') {

    but this will:

    Java Code:
    if (userChoice != 'r') {
    See the difference?

    Also when we see many many errors in a class, it suggests that you're not compiling often enough. You should only add a little bit of code at a time, such as one line at a time, and then compile. If there are any compilation errors, you should fix the errors before trying to add any more code.

  8. #8
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    Java Code:
    
    import java.util.Scanner;
    import java.util.Random;
    
     
    public class RockPaperScissor{
    
        public static void main(String [] args){
    
             
    
            int computerRandom;
    
            String userInput = "";
    
            char userChoice = 'j' ;
    
            char computerChoice = 'j';
    
            int computerWin = 0;
    
            int userWin = 0;
    
             
    
            Random random = new Random();
    
            Scanner reader = new Scanner (System.in);
    
                          
    
                while(userChoice != 'r' && userChoice != 'p' && userChoice != 's'){
    
    
                        System.out.print("\nPlease input r for Rock p for Paper or s for Scissor: ");
    
    
                         userInput = reader.nextLine();
    
                        userChoice = userInput.charAt(0);
    
                        System.out.print("\n" +userChoice);
                }
    
    
                computerRandom = random.nextInt(3);
    
    
              switch (computerRandom){
    
                    case 1: computerChoice = 'r'; break;
    
                    case 2: computerChoice = 'p'; break;
    
                    case 3: computerChoice = 's'; break;
    
                }
    
    
                if (computerChoice == userChoice){
    
                    System.out.print("\nTie ");
    
                }else{
    
                    if (computerChoice  == 'r'){
    
                        if (userChoice == 'p'){
    
                            System.out.print("\nPaper beats rock, you win!");
                            userWin++;
    
                        }
    
                        if (userChoice == 's'){
    
                            System.out.print("\nRock beats scissor, you lose!");
    
                            computerWin++;
    
                        }
    
                    }
    
                    if (computerChoice  == 'p'){
    
                        if (userChoice == 'r'){
    
                            System.out.print("\nPaper beats rock, you lose!");
    
                            computerWin++;
    
                        }
    
                        if (userChoice == 's'){
    
                            System.out.print("\nScissors beat paper, you win!");
    
                            userWin++;
    
                        }
    
                    }
    
                    if (computerChoice  == 's'){
    
                        if (userChoice == 'r'){
    
                            System.out.print("\nRock beats Scissor, you lose!");
    
                            computerWin++;
    
                        }
    
                        if (userChoice == 'p'){
    
                            System.out.print("\nPaper beats rock, you win!");
    
                            userWin++;
    
                        }
    
                   }
    
                }
    
                System.out.print("\nThe score is: user: " + userWin + " computer: " + computerWin);
    
            }
    
        }

    like this?

Similar Threads

  1. Paper rock Scissors Game inheritance problem
    By kaanax in forum New To Java
    Replies: 7
    Last Post: 08-20-2010, 03:44 PM
  2. Rock, Paper, Scissor Game Help
    By CYANiDE in forum New To Java
    Replies: 6
    Last Post: 10-28-2009, 05:20 PM
  3. Need Help with Rock paper and Scissors Java Game
    By kingsun in forum New To Java
    Replies: 3
    Last Post: 11-17-2008, 04:35 AM
  4. Need help with Rock Paper Scissors Game
    By GettinGwap in forum New To Java
    Replies: 12
    Last Post: 10-19-2008, 07:15 PM
  5. Paper,Scissor,Rock If then Statements
    By Alberto in forum New To Java
    Replies: 2
    Last Post: 02-12-2008, 12:18 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •