• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Rock, paper scissors error

 
Sara Bear
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



can not figure out how to fix the illegal start of expression for my playerAnswer function. Anybody have any ideas for me?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, and welcome to the Ranch!

When posting code please UseCodeTags(←click) so it will be readable. I've added them for you here.

Also, both when editing your code on your computer and when posting here, use spaces for indenting, not tabs. That will improve readability. I've done that for you here too.

Compiler errors are usually pretty direct and clear about exactly what's going wrong, but "Illegal start of expression" is a trickier one. It means the compiler has gotten confused as to where in the program it is (as opposed to something simpler like "I know I'm reading the name of a method you're calling, but there is no such method"). Usually because of missing or extra braces. In this case, it's seeing the declaration for your playerAnswer() method and saying, "This doesn't belong here." The reason is, if you look right above that, you'll see that you didn't put a close brace at the end of your main() method. I don't know if that was just an oversight or if you were trying to define one method inside another, but you can't do that.

So next time you see that error message, double check your braces!
 
sai rama krishna
Ranch Hand
Posts: 432
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i see random not declared propery and no implementation for method getwinner();
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're getting more errors and you can't figure them out after reading the error messages very closely and carefully and looking closely and carefully at the lines they're complaining about, then please post your current code, copy/paste the exact, complete error messages, and indicate clearly which lines are causing them.
 
Sara Bear
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



RockPaperScissors.java:43: error: invalid method declaration; return type requir
ed
getwinner(player, computer)
^
RockPaperScissors.java:43: error: <identifier> expected
getwinner(player, computer)
^
RockPaperScissors.java:43: error: <identifier> expected
getwinner(player, computer)
^
RockPaperScissors.java:58: error: illegal start of type
while (player == computer)
^
RockPaperScissors.java:58: error: <identifier> expected
while (player == computer)
^
RockPaperScissors.java:58: error: ';' expected
while (player == computer)
^
RockPaperScissors.java:58: error: illegal start of type
while (player == computer)
^
RockPaperScissors.java:59: error: ';' expected
System.out.print("Tie, Please select again);
^
RockPaperScissors.java:59: error: <identifier> expected
System.out.print("Tie, Please select again);
^
RockPaperScissors.java:59: error: unclosed string literal
System.out.print("Tie, Please select again);
^
RockPaperScissors.java:70: error: reached end of file while parsing
11 errors



Then I am supposed to validate case-insensitve player answers. cannot even think that far ahead!
 
Sara Bear
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sai rama krishna wrote:i see random not declared propery and no implementation for method getwinner();


I am not even sure what that means.......
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have this:



At the line I've labeled #1, you are declaring the method computerRandom(). You are properly indicating its return type (String) and you also give some additional information--you state that it's public and static. In the following lines, you provide that method's body.

At #2, the close brace ends that method. You should put a blank line after that.

At #3, thought it's harder to see without the blank line, it looks like you're declaring another method called getwinner(). But you didn't indicate a return type. That's why it's giving you the method "return type required" for that line.

Also, you should use camel case: getWinner, rather than getwinner. That's not an error, but if you follow conventions it will be easier for others to understand your code.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sara Bear wrote:
sai rama krishna wrote:i see random not declared propery and no implementation for method getwinner();


I am not even sure what that means.......


You have this:

What type is the "random" variable? You haven't declared it.
 
Aj Prieto
Ranch Hand
Posts: 75
Android Chrome Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also in your print statment in your while loop, your missing a " at the end of the sentence.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic