• Post Reply Bookmark Topic Watch Topic
  • New Topic

GuessGame  RSS feed

 
Manish Daryani
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone tell me how to run this code ?

I have written everything in a notepad file. How do i save this file ? GuessGame.java or something else ?
while compiling, I'm trying javac GuessGame.java but I am getting errors like class Gamelauncher is public, should be declared in a file named Gamelauncher.java . Same error for player class.

Can anyone tell me step by step as to how to run this code in command prompt.
Thanks

So here it is, here the GuessGame Code from the book:

 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gamelauncher is public, should be declared in a file named Gamelauncher.java

The error message explains the problem.  public classes must be defined in a file with the same name as the class has.  Rename the file to Gamelauncher.java
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When posting error messages please cut and paste the message don't type it in as you can make typing mistakes which can lead to us giving you incorrect advice.

In this case you have typed "Gamelauncher is public, should be declared in a file named Gamelauncher.java" when it should have been "GameLauncher is public, should be declared in a file named GameLauncher.java". This has resulted in Norm telling you to save it in a file called "Gamelauncher.java" when it should be saved in a file called "GameLauncher.java". Remember, Java is case sensitive.
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This Wiki article has a lot of useful information in it about running your first program.  You have already gotten a lot of it.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that from Head First Java? Did you copy the code from the book or download it? Beware: the downloaded code has package names in, and compiling will be easier if you delete the pacakge names. Look for a line starting package; it sh‍ould be at the beginning of each file.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!