Results 1 to 8 of 8
Thread: Rock, paper scissor game
- 02-03-2011, 09:05 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 5
- Rep Power
- 0
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?
-
Please first show us your attempt to solve this.
- 02-06-2011, 07:54 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 5
- Rep Power
- 0
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.
- 02-06-2011, 08:22 PM #5
Member
- Join Date
- Feb 2011
- Posts
- 5
- Rep Power
- 0
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); } }
- 02-06-2011, 08:31 PM #6
Member
- Join Date
- Feb 2011
- Posts
- 5
- Rep Power
- 0
did that work?
-
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:
See the difference?Java Code:if (userChoice != 'r') {
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.
- 02-06-2011, 08:43 PM #8
Member
- Join Date
- Feb 2011
- Posts
- 5
- Rep Power
- 0
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
-
Paper rock Scissors Game inheritance problem
By kaanax in forum New To JavaReplies: 7Last Post: 08-20-2010, 02:44 PM -
Rock, Paper, Scissor Game Help
By CYANiDE in forum New To JavaReplies: 6Last Post: 10-28-2009, 04:20 PM -
Need Help with Rock paper and Scissors Java Game
By kingsun in forum New To JavaReplies: 3Last Post: 11-17-2008, 03:35 AM -
Need help with Rock Paper Scissors Game
By GettinGwap in forum New To JavaReplies: 12Last Post: 10-19-2008, 06:15 PM -
Paper,Scissor,Rock If then Statements
By Alberto in forum New To JavaReplies: 2Last Post: 02-11-2008, 11:18 PM


LinkBack URL
About LinkBacks


Bookmarks