• Post Reply Bookmark Topic Watch Topic
  • New Topic

Paper, rock, scissors game help  RSS feed

 
Scott Dunning
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a couple quick questions. FYI, I am taking a class in college and it’s beginning Java and this is only my second week, so I'm super new.

I had a paper rock, scissors game as an assignment that was due a couple days ago. I ended up having to submit an not working file but, I’d like to figure out what I’m doing wrong for future assignments.

I feel like it’s correct and I got it down to just one error (reached end of file while parsing). I think that means that it needs an extra } at the end, but if I add one I go from one to 17 errors. I’m thinking maybe there is something wrong with my while loop or how I created a new function (or method in java, I had a class in python last semester so I’m not 100% sure I got the functions in java down yet). What makes sense to me and how I understand it is, the function itself must be created outside of main, but actually called in main? Also, are all of the functions going to be in the class RPS_Game? We haven’t really learned classes yet this is just my second week.

Here is my code, any help is greatly appreciated!


 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

My first advice is: never write this much code without compiling it many times along the way. There is no way anyone (even a seasoned pro) can write 80 lines of code and it will just work.

As to errors, yes, there is a closing bracket missing at the end. Before the file is syntactically correct, the compiler will not even check for semantic correctness, which is why it didn't report the other problems before.

The first thing that jumps out at me is the "player1 == "P" " comparisons - chars are enclosed in single quotes, not double quotes. Anything that has double quotes around it will be treated as a String object, not as a char (and strings are compared using the "equals" method, not using "=="). This is also a problem in lines 11, 12 and 13, but since those 3 variables aren't used you can just delete them.

One problem I see is the semicolon on line 22 - while it is syntactically correct there, it alters the meaning of the code in a way you don't want - remove it.

Lastly, the winningPlayer method does not always return something. What should happen is player1 is neither 'P' nor 'R' nor 'S'? You need to return some kind of error value, and check that in the main method.

There may be more issues, but that's what I noticed at a quick glance.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!