r/javahelp • u/moe0721 • Oct 21 '15
Im doing a rock paper scissors program in my class, Need help fixing it.
When I enter rock/paper/scissors it prints out text that is not supposed to apply.here is what happenes when you type in anything that is paper/rock/scissors
User wins, Scissors cuts threw paper User losses, Rock Smashes scissors User Ties with Computer User Ties Paper does not beat paper User losses to Scissors, it cuts right through your soul User beats rock, it covers the rock User ties with rock,you are stuck between a rock and a hard place User Losses to paper, it covers all you like a blanket User Wins against scissors, it smashes it to pieces
Scanner scan = new Scanner(System.in); String opp = "dfDF"; String user; int answer,wins = 0,losses = 0,ties = 0; String Rock = "rock"; String Paper = "paper"; String Scissors = "scissors"; System.out.println("Welcome to Rock paper Scisscors "); System.out.println("Enter an answer"); user = scan.nextLine(); answer = (int) Math.random()*3+1; if (answer == 1){ opp=Rock;
} if (answer == 2){ opp=Paper; } if (answer == 3){ opp=Scissors; } if (user.equals(Scissors) && opp.equals(Paper)); { System.out.println("User wins, Scissors cuts threw paper"); wins++; } if (user.equals(Scissors) && opp.equals(Rock)); { System.out.println("User losses, Rock Smashes scissors"); losses++; } if (user.equals(Scissors) && opp.equals(Scissors)); { System.out.println("User Ties with Computer"); ties++; } if (user.equals(Paper) && opp.equals(Paper)); { System.out.println("User Ties Paper does not beat paper"); ties++; } if (user.equals(Paper) && opp.equals(Scissors)); { System.out.println("User losses to Scissors, it cuts right through your soul"); losses++; } if (user.equals(Paper) && opp.equals(Rock)); { System.out.println("User beats rock, it covers the rock"); wins++; } if (user.equals(Rock) && opp.equals(Rock)); { System.out.println("User ties with rock,you are stuck between a rock and a hard place"); ties++; } if (user.equals(Rock) && opp.equals(Paper)); { System.out.println("User Losses to paper, it covers all you like a blanket"); losses++; } if (user.equals(Rock) && opp.equals(Scissors)); { System.out.println("User Wins against scissors, it smashes it to pieces"); wins++; } System.out.println(); System.out.println ("You won " + wins + " times."); System.out.println ("You lost " + losses + " times."); System.out.println ("We tied " + ties + " times.");
3
u/empire539 "empire"+(((int)-~(byte)+('\''&~'&')<<(' '>>('+'+~'(')))+0x1b); Oct 21 '15
Please format your code properly. See the sidebar for code posting guidelines.
3
u/aqua_regis Oct 21 '15
Dear OP,
If you want get help, you need to prepare a proper post.
A proper post consists of - in the order listed:
A good title - yours is OK
A description of what you want to achieve - is ok, but should be formatted as a bulleted (or numbered list), see the formatting help below the text entry box.
A description of what your problems are - how the output differs from the expectation and anything relevant
The error messages in full that you get, if any.
The code - formatted or on one of the code hosts is explained in both, the sidebar and in the Code Posting Guide
Any additional information you deem relevant to your problems
Your post fails at formatting in general. The quality of the visual representation of a post is directly proportional to the amount of attention and thus help it will get.
Your post fails to explain your problems, or the explanation is somewhere hidden in your wall of text
You failed to format the code. Nobody will be willing to format the code by themselves so that they can decipher your problem.
You are asking for help. So it is your responsibility to make it as easy as possible to help you. We dedicate our knowledge and time to help you, so as a token of appreciation for the help you are going to receive, you need to spend the minimum effort necessary to prepare a proper post.
Please, read and follow:
Thank you.
2
u/stuie382 Oct 21 '15
Aside from formatting your code, set a breakpoint are the beginning and step through the code with a debugger one line at a time and check out what your variables are at each step. This will show you where you have gone wrong.
Also it's through, not threw
4
u/[deleted] Oct 21 '15
format your code.