Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-16-2008, 10:39 AM
GettinGwap's Avatar
Member
 
Join Date: Oct 2008
Posts: 8
GettinGwap is on a distinguished road
Need help with Rock Paper Scissors Game
Hey I'm new to the forums and to Java. I have been writing a rock, paper, scissors game and almost everything seems to be in order. But I have a line of code that contains an error I cannot catch. The compiler says "illegal start of expression when the game ends and prints the users statistics. Here's the code:

// Author:
// Started: October 14, 2008
// Finished:
//
// Game of Rock, Paper, Scissors
//

import jpb.*;

public class RPS
{
public static void main(String[ ] args)
{

// Instance variables
int wins = 0;
int losses = 0;
int draws = 0;
boolean repeat = true;

// Loop so the program can run as many times
// as the user would like
while(repeat = true)
{
SimpleIO.prompt("Rock, paper, or scissors?");
String choice = SimpleIO.readline( );

if(choice.equalsIgnoreCase("rock"))
{
System.out.println("You lose");
losses ++;
}
else if(choice.equalsIgnoreCase("paper"))
{
System.out.print("It's a draw");
draws ++;
}
else if(choice.equalsIgnoreCase("scissors"))
{
System.out.println("You win!");
wins ++;
}
else
{
System.out.println("I'm sorry, that's not an answer");
SimpleIO.prompt("Rock, paper, or scissors?");
String choice = SimpleIO.readline( );
}

// Asks the user if they want to continue
SimpleIO.prompt("Play again?");
String decision = SimpleIO.readline( );

if(decision.equalsIgnoreCase("yes"))
repeat =true;
else if (decision.equalsIgnoreCase("no"))
{
repeat = false;
// Prints the user's stats
System.out.print(wins + " wins " + losses + " losses " + );
System.out.print(draws + " draws");
}
// Displays a message depending on performance
if (wins > losses)
{
System.out.println("Good job, thanks for playing.");
}
else
{
System.out.println("It wasn't your best day.");
}

else if
{
SimpleIO.prompt("That is not an option. Play again?");
String decision = SimpleIO.readline( );
}

}
}
}
}

The error is in the two lines that print the user's stats in the middle of the program. This may seem elementary, but I am very new to Java. Thanks in advance.
__________________
$GettinGwap$
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-16-2008, 11:35 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
C:\jexp>javac rps.java rps.java:51: illegal start of expression System.out.print(wins + " wins " + losses + " losses " + ); ^ rps.java:64: 'else' without 'if' else if ^ rps.java:71: class, interface, or enum expected } ^ 3 errors
on line 51: change this
Code:
System.out.print(wins + " wins " + losses + " losses " + );
to this
Code:
System.out.print(wins + " wins " + losses + " losses ");
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-16-2008, 12:35 PM
GettinGwap's Avatar
Member
 
Join Date: Oct 2008
Posts: 8
GettinGwap is on a distinguished road
thanks
thanks that pretty much fixed it. It's amazing how you can overlook such things.
__________________
$GettinGwap$
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 10-17-2008, 04:52 AM
GettinGwap's Avatar
Member
 
Join Date: Oct 2008
Posts: 8
GettinGwap is on a distinguished road
reached end of file while parsing
the program is almost error free. but the IDE I am running and even DOS highlights my last curly brace and says 'reached end of file while parsing'. I tried adding and taking away curly braces and have gotten varied but unwanted results. Taking one away gives me more errors in dealing with my input statements. Adding one also gives me errors with my input statements. Any suggestions or explanations?
__________________
$GettinGwap$
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 10-17-2008, 06:13 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Some IDEs have logic to find the matching brace. Check yours.

Otherwise, print out the source and take a pencil and connect the pairs of braces until you find the missing one. Work from the inside out.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 10-17-2008, 08:46 AM
GettinGwap's Avatar
Member
 
Join Date: Oct 2008
Posts: 8
GettinGwap is on a distinguished road
confusing
Wow when I added the matching braces (it's equal now) there are four errors in the program each dealing with my input statements. On every line that contains "string x = SimpleIO.readline()". The error message is "cannot find symbol" (new line) "symbol : method readline()" (new line)
"location: class jpb.SimpleIO"

Is the compiler telling me that SimpleIO isn't in the package I used? What about the readline() method? It wasn't saying that before I evened the curly braces.
__________________
$GettinGwap$
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 10-17-2008, 11:13 AM
Senior Member
 
Join Date: Sep 2008
Posts: 235
Darryl.Burke is on a distinguished road
As SimpleIO isn't a class in the standard JDK, you need to ask wherever you got that class from.

About mismatching braces: learn to indent your code correctly and it'll never happen again. Well, almost never.
Code Conventions for the Java(TM) Programming Language: Contents

luck, db
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 10-17-2008, 04:33 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
IF the missing class (SimpleIO) is in a jar file, you need to add that jar file to the classpath when you compile and execute your program so that the javac and java programs can find it.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 10-17-2008, 05:59 PM
Senior Member
 
Join Date: Aug 2008
Posts: 178
Supamagier is on a distinguished road
You have this
Code:
else { System.out.println("It wasn't your best day."); } else if {
and a bracket mismatch somewhere.

And if you're sure it is where it should be, it probably is readLine(), with a capital L
__________________
check out
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
, 100% made by me.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 10-19-2008, 06:29 PM
GettinGwap's Avatar
Member
 
Join Date: Oct 2008
Posts: 8
GettinGwap is on a distinguished road
My code was indented, but when i pasted it, it wasn't shown that way. Yes capitalizing the readLine worked, but now it is saying that my string variable that is the user's decision, is already defined in main. I don't understand how I can get 1 error after another. It's like Java is never satisfied. Getting kind of frustrating.
__________________
$GettinGwap$

Last edited by GettinGwap : 10-19-2008 at 06:39 PM.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 10-19-2008, 06:39 PM
ojn ojn is offline
Member
 
Join Date: Sep 2008
Location: Stockholm, Sweden
Posts: 54
ojn is on a distinguished road
Send a message via MSN to ojn
Use the CODE or PHP tags to get indentation.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 10-19-2008, 07:31 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
You need to post the FULL text of the error messages so we can see what and where the errors are.
Quote:
is already defined
for example:
int aInt = 123;
...
int aInt = 45; // here aInt is already defined above
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 10-19-2008, 08:15 PM
GettinGwap's Avatar
Member
 
Join Date: Oct 2008
Posts: 8
GettinGwap is on a distinguished road
I finally got it to work. Thank you for sticking with me the enitre time. That was my first program that I attempted on my own outside of schoolwork. Again thanks. Now I want to put it on my phone. It is an LG Fusic. I googled it but I found most people were concerned with ring tones.
__________________
$GettinGwap$

Last edited by GettinGwap : 10-19-2008 at 08:28 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SCJP 1.5 dump paper uttam kumar bhatta Professional Certification 1 11-27-2008 09:04 AM
game amith AWT / Swing 0 05-19-2008 07:16 PM
Paper,Scissor,Rock If then Statements Alberto New To Java 2 02-12-2008 01:18 AM
urgent help needed - paper submission. dirtycash New To Java 2 11-23-2007 01:24 PM
Implementing "Game Over" in Minesweeper game based on Gridworld framework. JFlash New To Java 0 11-16-2007 01:02 AM


All times are GMT +3. The time now is 10:35 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org